
<!DOCTYPE html>
<html
  lang="zh-cn"
  data-figures=""
  
    class="page"
  
  
  >
  <head>
<title>Linux内核copy_process分析（二） | 拾月国度</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script>
  var _hmt = _hmt || [];
  (function() {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?c24bad48a3da8c3c532f0c580bb4f8c5";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
  })();
</script>





<meta property="og:locale" content="zh-cn" />

<meta property="og:type" content="article">
<meta name="description" content="1. shm_init_task 在使能SYSVIPC的情况下，初始化task-&gt;sysvshm.shm_clist。
1 /* copy all the process information */ 2 shm_init_task(p); 2. security_task_alloc 1 retval = …" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:creator" content="">
<meta name="twitter:title" content="Linux内核copy_process分析（二）" />
<meta name="twitter:image" content="https://kingdix10.gitee.io/covers/cover8.jpg"/>
<meta property="og:url" content="https://kingdix10.gitee.io/post/kernel/linux-6.6/sched/copy_process_2/" />
<meta property="og:title" content="Linux内核copy_process分析（二）" />
<meta property="og:description" content="1. shm_init_task 在使能SYSVIPC的情况下，初始化task-&gt;sysvshm.shm_clist。
1 /* copy all the process information */ 2 shm_init_task(p); 2. security_task_alloc 1 retval = …" />
<meta property="og:image" content="https://kingdix10.gitee.io/covers/cover8.jpg" />

<link rel="apple-touch-icon" sizes="180x180" href="https://kingdix10.gitee.io/icons/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="https://kingdix10.gitee.io/icons/icon_yellow_transparent.png">
<link rel="manifest" href="https://kingdix10.gitee.io/icons/site.webmanifest">

<link rel="canonical" href="https://kingdix10.gitee.io/post/kernel/linux-6.6/sched/copy_process_2/">



<link rel="preload" href="https://kingdix10.gitee.io/css/styles.42e2c5f6d8cf9c52872666f8d8b2678ad0c426978b9d78aff3c33b7a1e7f6f97f54bcdaf0518a25fb0fe26367d04f8b07c683b3b38b331cb098daadee06b1f3e.css" integrity = "sha512-QuLF9tjPnFKHJmb42LJnitDEJpeLnXiv88M7eh5/b5f1S82vBRiiX7D&#43;JjZ9BPiwfGg7OzizMcsJjare4GsfPg==" as="style" crossorigin="anonymous">



<link rel="preload" href="https://kingdix10.gitee.io/zh-cn/js/bundle.352f6b8ac853443fc909370d968a769ffa303b36042cc66849f2d48d9e5dd951ee86c06130908f5d77ea0e55ec8fed0e5dc26f0f14bbd4ad6dcf35999232e5bc.js" as="script" integrity=
"sha512-NS9rishTRD/JCTcNlop2n/owOzYELMZoSfLUjZ5d2VHuhsBhMJCPXXfqDlXsj&#43;0OXcJvDxS71K1tzzWZkjLlvA==" crossorigin="anonymous">


<link rel="stylesheet" type="text/css" href="https://kingdix10.gitee.io/css/styles.42e2c5f6d8cf9c52872666f8d8b2678ad0c426978b9d78aff3c33b7a1e7f6f97f54bcdaf0518a25fb0fe26367d04f8b07c683b3b38b331cb098daadee06b1f3e.css" integrity="sha512-QuLF9tjPnFKHJmb42LJnitDEJpeLnXiv88M7eh5/b5f1S82vBRiiX7D&#43;JjZ9BPiwfGg7OzizMcsJjare4GsfPg==" crossorigin="anonymous">

  </head>
  <body
    data-code="9"
    data-lines="true"
    id="documentTop"
    data-lang="zh-cn"
  >

<header class="nav_header" >
  <nav class="nav"><a href='https://kingdix10.gitee.io/' class="nav_brand nav_item" title="拾月国度">
  <img src="https://kingdix10.gitee.io/logos/icon_yellow_transparent_72x72.png" class="logo" alt="拾月国度">
  <div class="nav_close">
    <div><svg class="icon">
  <title>open-menu</title>
  <use xlink:href="#open-menu"></use>
</svg>
<svg class="icon">
  <title>closeme</title>
  <use xlink:href="#closeme"></use>
</svg>
</div>
  </div>
</a>

    <div class='nav_body nav_body_left'>
      
      
      
        

  <div class="nav_parent">
    <a href="https://kingdix10.gitee.io/home" class="nav_item" title="主页">主页 </a>
  </div>
  <div class="nav_parent">
    <a href="https://kingdix10.gitee.io/" class="nav_item" title="归档">归档 </a>
  </div>
  <div class="nav_parent">
    <a href="https://kingdix10.gitee.io/" class="nav_item" title="链接">链接 <img src='https://kingdix10.gitee.io/icons/caret-icon.svg' alt="icon" class="nav_icon"></a>
    <div class="nav_sub">
      <span class="nav_child"></span>
        <a href="https://gitee.com/kingdix10" class="nav_child nav_item" title="Gitee">Gitee</a>
        <a href="https://github.com/kingdix10" class="nav_child nav_item" title="GitHub">GitHub</a>
        <a href="https://www.zhihu.com/people/kingdix10" class="nav_child nav_item" title="知乎">知乎</a>
        <a href="https://www.cnblogs.com/kingdix10" class="nav_child nav_item" title="博客园">博客园</a>
        <a href="https://blog.csdn.net/u014001096" class="nav_child nav_item" title="CSDN">CSDN</a>
    </div>
  </div>
  <div class="nav_parent">
    <a href="https://kingdix10.gitee.io/about/" class="nav_item" title="关于">关于 </a>
  </div>
      
      <div class="nav_parent">
        <a href="#" class="nav_item">🌐</a>
        <div class="nav_sub">
          <span class="nav_child"></span>
          
          <a href="https://kingdix10.gitee.io/" class="nav_child nav_item">中文</a>
          
          <a href="https://kingdix10.gitee.io/en/" class="nav_child nav_item">English</a>
          
        </div>
      </div>
<div class='follow'>
  <a href="https://gitee.com/kingdix10">
    <svg class="icon">
  <title>gitee</title>
  <use xlink:href="#gitee"></use>
</svg>

  </a>
  <a href="https://github.com/kingdix10">
    <svg class="icon">
  <title>github</title>
  <use xlink:href="#github"></use>
</svg>

  </a>
    
  <a href="https://kingdix10.gitee.io/index.xml">
    <svg class="icon">
  <title>rss</title>
  <use xlink:href="#rss"></use>
</svg>

  </a>
<div class="color_mode">
  <input type="checkbox" class="color_choice" id="mode">
</div>

</div>

    </div>
  </nav>
</header>

    <main>
<div class="grid-inverse wrap content">
  <article class="post_content">
    <h1 class="post_title">Linux内核copy_process分析（二）</h1>
  <div class="post_meta">
    <span><svg class="icon">
  <title>calendar</title>
  <use xlink:href="#calendar"></use>
</svg>
</span>
    <span class="post_date">
      2022/02/14</span>
    <span class="post_time"> | 9 分钟阅读</span><span>&nbsp;|<a href='https://kingdix10.gitee.io/tags/linux/' title="Linux" class="post_tag button button_translucent">Linux
        </a><a href='https://kingdix10.gitee.io/tags/linux-6.6/' title="linux-6.6" class="post_tag button button_translucent">linux-6.6
        </a>
    </span>
    <span class="page_only">&nbsp;|
  <div class="post_share">
    分享到:

    <a href="https://kingdix10.gitee.io/post/kernel/linux-6.6/sched/copy_process_2/" title="Copy Link" class="link link_yank">
      <svg class="icon">
  <title>copy</title>
  <use xlink:href="#copy"></use>
</svg>

    </a>
  </div>
  
</span>
  </div>



      <div class="post_toc">
        <h2>文章目录</h2>
        <nav id="TableOfContents">
  <ul>
    <li><a href="#1-shm_init_task">1. shm_init_task</a></li>
    <li><a href="#2-security_task_alloc">2. security_task_alloc</a></li>
    <li><a href="#3-copy_semundo">3. copy_semundo</a>
      <ul>
        <li><a href="#31-copy_semundo源码">3.1. copy_semundo源码</a></li>
      </ul>
    </li>
    <li><a href="#4-copy_files">4. copy_files</a>
      <ul>
        <li><a href="#41-copy_files源码">4.1. copy_files源码</a></li>
        <li><a href="#42-dup_fd原型">4.2. dup_fd原型</a></li>
      </ul>
    </li>
    <li><a href="#5-copy_fs">5. copy_fs</a>
      <ul>
        <li><a href="#51-copy_fs源码">5.1. copy_fs源码</a></li>
        <li><a href="#52-copy_fs_struct源码">5.2. copy_fs_struct源码</a></li>
      </ul>
    </li>
    <li><a href="#6-copy_sighand">6. copy_sighand</a>
      <ul>
        <li><a href="#61-copy_sighand源码">6.1. copy_sighand源码</a></li>
      </ul>
    </li>
    <li><a href="#7-copy_signal">7. copy_signal</a>
      <ul>
        <li><a href="#71-copy_signal源码">7.1. copy_signal源码</a></li>
      </ul>
    </li>
    <li><a href="#8-copy_mm">8. copy_mm</a>
      <ul>
        <li><a href="#81-copy_mm源码">8.1. copy_mm源码</a></li>
      </ul>
    </li>
    <li><a href="#9-copy_namespaces">9. copy_namespaces</a>
      <ul>
        <li><a href="#91-copy_namespaces源码">9.1. copy_namespaces源码</a></li>
        <li><a href="#92-create_new_namespaces源码">9.2. create_new_namespaces源码</a></li>
        <li><a href="#93-timens_on_fork">9.3. timens_on_fork</a></li>
      </ul>
    </li>
    <li><a href="#10-copy_io">10. copy_io</a>
      <ul>
        <li><a href="#101-copy_io源码">10.1. copy_io源码</a></li>
        <li><a href="#102-__copy_io源码">10.2. __copy_io源码</a></li>
      </ul>
    </li>
    <li><a href="#11-copy_thread">11. copy_thread</a>
      <ul>
        <li><a href="#111-arm64-copy_thread源码">11.1. ARM64 copy_thread源码</a></li>
      </ul>
    </li>
  </ul>
</nav>
      </div>
    
    <div class="post_body"><h1 id="1-shm_init_task">1. shm_init_task</h1>
<p>在使能SYSVIPC的情况下，初始化<code>task-&gt;sysvshm.shm_clist</code>。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln">1</span><span class="cl">    <span class="cm">/* copy all the process information */</span>
</span></span><span class="line"><span class="ln">2</span><span class="cl">    <span class="nf">shm_init_task</span><span class="p">(</span><span class="n">p</span><span class="p">);</span>
</span></span></code></pre></div><h1 id="2-security_task_alloc">2. security_task_alloc</h1>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln">1</span><span class="cl">    <span class="n">retval</span> <span class="o">=</span> <span class="nf">security_task_alloc</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">clone_flags</span><span class="p">);</span>   <span class="c1">/// Allocate a task&#39;s LSM blob
</span></span></span><span class="line"><span class="ln">2</span><span class="cl"><span class="c1"></span>    <span class="k">if</span> <span class="p">(</span><span class="n">retval</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">3</span><span class="cl">        <span class="k">goto</span> <span class="n">bad_fork_cleanup_audit</span><span class="p">;</span>
</span></span></code></pre></div><h1 id="3-copy_semundo">3. copy_semundo</h1>
<p>在不使能CONFIG_SYSVIPC的情况下，copy_semundo为空。如果clone_flags包含CLONE_SYSVSEM，则共享父进程的sysvsem.undo_list，或者申请新的undo_list。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln">1</span><span class="cl">    <span class="n">retval</span> <span class="o">=</span> <span class="nf">copy_semundo</span><span class="p">(</span><span class="n">clone_flags</span><span class="p">,</span> <span class="n">p</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">2</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="n">retval</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">3</span><span class="cl">        <span class="k">goto</span> <span class="n">bad_fork_cleanup_security</span><span class="p">;</span>
</span></span></code></pre></div><h2 id="31-copy_semundo源码">3.1. copy_semundo源码</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln"> 1</span><span class="cl"><span class="c1">/// ipc/sem.c
</span></span></span><span class="line"><span class="ln"> 2</span><span class="cl"><span class="c1"></span><span class="cm">/* If CLONE_SYSVSEM is set, establish sharing of SEM_UNDO state between
</span></span></span><span class="line"><span class="ln"> 3</span><span class="cl"><span class="cm"> * parent and child tasks.
</span></span></span><span class="line"><span class="ln"> 4</span><span class="cl"><span class="cm"> */</span>
</span></span><span class="line"><span class="ln"> 5</span><span class="cl">
</span></span><span class="line"><span class="ln"> 6</span><span class="cl"><span class="kt">int</span> <span class="nf">copy_semundo</span><span class="p">(</span><span class="kt">unsigned</span> <span class="kt">long</span> <span class="n">clone_flags</span><span class="p">,</span> <span class="k">struct</span> <span class="n">task_struct</span> <span class="o">*</span><span class="n">tsk</span><span class="p">)</span>
</span></span><span class="line"><span class="ln"> 7</span><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="ln"> 8</span><span class="cl">    <span class="k">struct</span> <span class="n">sem_undo_list</span> <span class="o">*</span><span class="n">undo_list</span><span class="p">;</span>
</span></span><span class="line"><span class="ln"> 9</span><span class="cl">    <span class="kt">int</span> <span class="n">error</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">10</span><span class="cl">
</span></span><span class="line"><span class="ln">11</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="n">clone_flags</span> <span class="o">&amp;</span> <span class="n">CLONE_SYSVSEM</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln">12</span><span class="cl">        <span class="c1">/// 如果当前进程sysvsem.undo_list不为空，则共享
</span></span></span><span class="line"><span class="ln">13</span><span class="cl"><span class="c1"></span>        <span class="c1">/// 否则为新进程分配新的undo_list
</span></span></span><span class="line"><span class="ln">14</span><span class="cl"><span class="c1"></span>        <span class="n">error</span> <span class="o">=</span> <span class="nf">get_undo_list</span><span class="p">(</span><span class="o">&amp;</span><span class="n">undo_list</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">15</span><span class="cl">        <span class="k">if</span> <span class="p">(</span><span class="n">error</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">16</span><span class="cl">            <span class="k">return</span> <span class="n">error</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">17</span><span class="cl">        <span class="nf">refcount_inc</span><span class="p">(</span><span class="o">&amp;</span><span class="n">undo_list</span><span class="o">-&gt;</span><span class="n">refcnt</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">18</span><span class="cl">        <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">sysvsem</span><span class="p">.</span><span class="n">undo_list</span> <span class="o">=</span> <span class="n">undo_list</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">19</span><span class="cl">    <span class="p">}</span> <span class="k">else</span>
</span></span><span class="line"><span class="ln">20</span><span class="cl">        <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">sysvsem</span><span class="p">.</span><span class="n">undo_list</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">21</span><span class="cl">
</span></span><span class="line"><span class="ln">22</span><span class="cl">    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">23</span><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><h1 id="4-copy_files">4. copy_files</h1>
<p>如果clone_flags包含CLONE_FILES，则与父进程共享files_struct，否则调用dup_fd创建新的files_struct。files_struct包含进程打开文件列表。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln">1</span><span class="cl">    <span class="n">retval</span> <span class="o">=</span> <span class="nf">copy_files</span><span class="p">(</span><span class="n">clone_flags</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">args</span><span class="o">-&gt;</span><span class="n">no_files</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">2</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="n">retval</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">3</span><span class="cl">        <span class="k">goto</span> <span class="n">bad_fork_cleanup_semundo</span><span class="p">;</span>
</span></span></code></pre></div><h2 id="41-copy_files源码">4.1. copy_files源码</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln"> 1</span><span class="cl"><span class="c1">/// kernel/fork.c
</span></span></span><span class="line"><span class="ln"> 2</span><span class="cl"><span class="c1"></span><span class="k">static</span> <span class="kt">int</span> <span class="nf">copy_files</span><span class="p">(</span><span class="kt">unsigned</span> <span class="kt">long</span> <span class="n">clone_flags</span><span class="p">,</span> <span class="k">struct</span> <span class="n">task_struct</span> <span class="o">*</span><span class="n">tsk</span><span class="p">,</span>
</span></span><span class="line"><span class="ln"> 3</span><span class="cl">              <span class="kt">int</span> <span class="n">no_files</span><span class="p">)</span>
</span></span><span class="line"><span class="ln"> 4</span><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="ln"> 5</span><span class="cl">    <span class="k">struct</span> <span class="n">files_struct</span> <span class="o">*</span><span class="n">oldf</span><span class="p">,</span> <span class="o">*</span><span class="n">newf</span><span class="p">;</span>
</span></span><span class="line"><span class="ln"> 6</span><span class="cl">    <span class="kt">int</span> <span class="n">error</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="ln"> 7</span><span class="cl">
</span></span><span class="line"><span class="ln"> 8</span><span class="cl">    <span class="cm">/*
</span></span></span><span class="line"><span class="ln"> 9</span><span class="cl"><span class="cm">     * A background process may not have any files ...
</span></span></span><span class="line"><span class="ln">10</span><span class="cl"><span class="cm">     */</span>
</span></span><span class="line"><span class="ln">11</span><span class="cl">    <span class="n">oldf</span> <span class="o">=</span> <span class="n">current</span><span class="o">-&gt;</span><span class="n">files</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">12</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">oldf</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">13</span><span class="cl">        <span class="k">goto</span> <span class="n">out</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">14</span><span class="cl">
</span></span><span class="line"><span class="ln">15</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="n">no_files</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln">16</span><span class="cl">        <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">files</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">17</span><span class="cl">        <span class="k">goto</span> <span class="n">out</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">18</span><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="ln">19</span><span class="cl">
</span></span><span class="line"><span class="ln">20</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="n">clone_flags</span> <span class="o">&amp;</span> <span class="n">CLONE_FILES</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln">21</span><span class="cl">        <span class="nf">atomic_inc</span><span class="p">(</span><span class="o">&amp;</span><span class="n">oldf</span><span class="o">-&gt;</span><span class="n">count</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">22</span><span class="cl">        <span class="k">goto</span> <span class="n">out</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">23</span><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="ln">24</span><span class="cl">
</span></span><span class="line"><span class="ln">25</span><span class="cl">    <span class="n">newf</span> <span class="o">=</span> <span class="nf">dup_fd</span><span class="p">(</span><span class="n">oldf</span><span class="p">,</span> <span class="n">NR_OPEN_MAX</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">error</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">26</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">newf</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">27</span><span class="cl">        <span class="k">goto</span> <span class="n">out</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">28</span><span class="cl">
</span></span><span class="line"><span class="ln">29</span><span class="cl">    <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">files</span> <span class="o">=</span> <span class="n">newf</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">30</span><span class="cl">    <span class="n">error</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">31</span><span class="cl"><span class="nl">out</span><span class="p">:</span>
</span></span><span class="line"><span class="ln">32</span><span class="cl">    <span class="k">return</span> <span class="n">error</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">33</span><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><h2 id="42-dup_fd原型">4.2. dup_fd原型</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln">1</span><span class="cl"><span class="c1">/// fs/file.c
</span></span></span><span class="line"><span class="ln">2</span><span class="cl"><span class="c1"></span><span class="cm">/*
</span></span></span><span class="line"><span class="ln">3</span><span class="cl"><span class="cm"> * Allocate a new files structure and copy contents from the
</span></span></span><span class="line"><span class="ln">4</span><span class="cl"><span class="cm"> * passed in files structure.
</span></span></span><span class="line"><span class="ln">5</span><span class="cl"><span class="cm"> * errorp will be valid only when the returned files_struct is NULL.
</span></span></span><span class="line"><span class="ln">6</span><span class="cl"><span class="cm"> */</span>
</span></span><span class="line"><span class="ln">7</span><span class="cl"><span class="k">struct</span> <span class="n">files_struct</span> <span class="o">*</span><span class="nf">dup_fd</span><span class="p">(</span><span class="k">struct</span> <span class="n">files_struct</span> <span class="o">*</span><span class="n">oldf</span><span class="p">,</span> <span class="kt">unsigned</span> <span class="kt">int</span> <span class="n">max_fds</span><span class="p">,</span> <span class="kt">int</span> <span class="o">*</span><span class="n">errorp</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">8</span><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="ln">9</span><span class="cl">    <span class="c1">/// ... ...
</span></span></span></code></pre></div><h1 id="5-copy_fs">5. copy_fs</h1>
<p>如果clone_flags包含CLONE_FS，则与父进程共享fs_struct，否则调用copy_fs_struct创建新的fs_struct。
fs_struct包含进程的根目录、当前目录等信息。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln">1</span><span class="cl">    <span class="n">retval</span> <span class="o">=</span> <span class="nf">copy_fs</span><span class="p">(</span><span class="n">clone_flags</span><span class="p">,</span> <span class="n">p</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">2</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="n">retval</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">3</span><span class="cl">        <span class="k">goto</span> <span class="n">bad_fork_cleanup_files</span><span class="p">;</span>
</span></span></code></pre></div><h2 id="51-copy_fs源码">5.1. copy_fs源码</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln"> 1</span><span class="cl"><span class="c1">/// kernel/fork.c
</span></span></span><span class="line"><span class="ln"> 2</span><span class="cl"><span class="c1"></span><span class="k">static</span> <span class="kt">int</span> <span class="nf">copy_fs</span><span class="p">(</span><span class="kt">unsigned</span> <span class="kt">long</span> <span class="n">clone_flags</span><span class="p">,</span> <span class="k">struct</span> <span class="n">task_struct</span> <span class="o">*</span><span class="n">tsk</span><span class="p">)</span>
</span></span><span class="line"><span class="ln"> 3</span><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="ln"> 4</span><span class="cl">    <span class="k">struct</span> <span class="n">fs_struct</span> <span class="o">*</span><span class="n">fs</span> <span class="o">=</span> <span class="n">current</span><span class="o">-&gt;</span><span class="n">fs</span><span class="p">;</span>
</span></span><span class="line"><span class="ln"> 5</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="n">clone_flags</span> <span class="o">&amp;</span> <span class="n">CLONE_FS</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln"> 6</span><span class="cl">        <span class="cm">/* tsk-&gt;fs is already what we want */</span>
</span></span><span class="line"><span class="ln"> 7</span><span class="cl">        <span class="nf">spin_lock</span><span class="p">(</span><span class="o">&amp;</span><span class="n">fs</span><span class="o">-&gt;</span><span class="n">lock</span><span class="p">);</span>
</span></span><span class="line"><span class="ln"> 8</span><span class="cl">        <span class="k">if</span> <span class="p">(</span><span class="n">fs</span><span class="o">-&gt;</span><span class="n">in_exec</span><span class="p">)</span> <span class="p">{</span>      <span class="c1">/// 正在执行execve系统调用？
</span></span></span><span class="line"><span class="ln"> 9</span><span class="cl"><span class="c1"></span>            <span class="nf">spin_unlock</span><span class="p">(</span><span class="o">&amp;</span><span class="n">fs</span><span class="o">-&gt;</span><span class="n">lock</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">10</span><span class="cl">            <span class="k">return</span> <span class="o">-</span><span class="n">EAGAIN</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">11</span><span class="cl">        <span class="p">}</span>
</span></span><span class="line"><span class="ln">12</span><span class="cl">        <span class="n">fs</span><span class="o">-&gt;</span><span class="n">users</span><span class="o">++</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">13</span><span class="cl">        <span class="nf">spin_unlock</span><span class="p">(</span><span class="o">&amp;</span><span class="n">fs</span><span class="o">-&gt;</span><span class="n">lock</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">14</span><span class="cl">        <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">15</span><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="ln">16</span><span class="cl">    <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">fs</span> <span class="o">=</span> <span class="nf">copy_fs_struct</span><span class="p">(</span><span class="n">fs</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">17</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">tsk</span><span class="o">-&gt;</span><span class="n">fs</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">18</span><span class="cl">        <span class="k">return</span> <span class="o">-</span><span class="n">ENOMEM</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">19</span><span class="cl">    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">20</span><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><h2 id="52-copy_fs_struct源码">5.2. copy_fs_struct源码</h2>
<p>新创建的fs_struct继承父进程fs_struct的一些数据。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln"> 1</span><span class="cl"><span class="c1">/// fs/fs_struct.c
</span></span></span><span class="line"><span class="ln"> 2</span><span class="cl"><span class="c1"></span><span class="k">struct</span> <span class="n">fs_struct</span> <span class="o">*</span><span class="nf">copy_fs_struct</span><span class="p">(</span><span class="k">struct</span> <span class="n">fs_struct</span> <span class="o">*</span><span class="n">old</span><span class="p">)</span>
</span></span><span class="line"><span class="ln"> 3</span><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="ln"> 4</span><span class="cl">    <span class="k">struct</span> <span class="n">fs_struct</span> <span class="o">*</span><span class="n">fs</span> <span class="o">=</span> <span class="nf">kmem_cache_alloc</span><span class="p">(</span><span class="n">fs_cachep</span><span class="p">,</span> <span class="n">GFP_KERNEL</span><span class="p">);</span>
</span></span><span class="line"><span class="ln"> 5</span><span class="cl">    <span class="cm">/* We don&#39;t need to lock fs - think why ;-) */</span>
</span></span><span class="line"><span class="ln"> 6</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="n">fs</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln"> 7</span><span class="cl">        <span class="n">fs</span><span class="o">-&gt;</span><span class="n">users</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
</span></span><span class="line"><span class="ln"> 8</span><span class="cl">        <span class="n">fs</span><span class="o">-&gt;</span><span class="n">in_exec</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="ln"> 9</span><span class="cl">        <span class="nf">spin_lock_init</span><span class="p">(</span><span class="o">&amp;</span><span class="n">fs</span><span class="o">-&gt;</span><span class="n">lock</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">10</span><span class="cl">        <span class="nf">seqcount_spinlock_init</span><span class="p">(</span><span class="o">&amp;</span><span class="n">fs</span><span class="o">-&gt;</span><span class="n">seq</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">fs</span><span class="o">-&gt;</span><span class="n">lock</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">11</span><span class="cl">        <span class="n">fs</span><span class="o">-&gt;</span><span class="n">umask</span> <span class="o">=</span> <span class="n">old</span><span class="o">-&gt;</span><span class="n">umask</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">12</span><span class="cl">
</span></span><span class="line"><span class="ln">13</span><span class="cl">        <span class="nf">spin_lock</span><span class="p">(</span><span class="o">&amp;</span><span class="n">old</span><span class="o">-&gt;</span><span class="n">lock</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">14</span><span class="cl">        <span class="n">fs</span><span class="o">-&gt;</span><span class="n">root</span> <span class="o">=</span> <span class="n">old</span><span class="o">-&gt;</span><span class="n">root</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">15</span><span class="cl">        <span class="nf">path_get</span><span class="p">(</span><span class="o">&amp;</span><span class="n">fs</span><span class="o">-&gt;</span><span class="n">root</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">16</span><span class="cl">        <span class="n">fs</span><span class="o">-&gt;</span><span class="n">pwd</span> <span class="o">=</span> <span class="n">old</span><span class="o">-&gt;</span><span class="n">pwd</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">17</span><span class="cl">        <span class="nf">path_get</span><span class="p">(</span><span class="o">&amp;</span><span class="n">fs</span><span class="o">-&gt;</span><span class="n">pwd</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">18</span><span class="cl">        <span class="nf">spin_unlock</span><span class="p">(</span><span class="o">&amp;</span><span class="n">old</span><span class="o">-&gt;</span><span class="n">lock</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">19</span><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="ln">20</span><span class="cl">    <span class="k">return</span> <span class="n">fs</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">21</span><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><h1 id="6-copy_sighand">6. copy_sighand</h1>
<p>如果clone_flags包含CLONE_SIGHAND，则共享父进程sighand。否则，创建一个新的sighand，并从父进程复制sighand-&gt;action。如果clone_flags包含CLONE_CLEAR_SIGHAND，还会将signal handler重置为默认值。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln">1</span><span class="cl">    <span class="n">retval</span> <span class="o">=</span> <span class="nf">copy_sighand</span><span class="p">(</span><span class="n">clone_flags</span><span class="p">,</span> <span class="n">p</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">2</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="n">retval</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">3</span><span class="cl">        <span class="k">goto</span> <span class="n">bad_fork_cleanup_fs</span><span class="p">;</span>
</span></span></code></pre></div><h2 id="61-copy_sighand源码">6.1. copy_sighand源码</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln"> 1</span><span class="cl"><span class="c1">/// kernel/fork.c
</span></span></span><span class="line"><span class="ln"> 2</span><span class="cl"><span class="c1"></span><span class="k">static</span> <span class="kt">int</span> <span class="nf">copy_sighand</span><span class="p">(</span><span class="kt">unsigned</span> <span class="kt">long</span> <span class="n">clone_flags</span><span class="p">,</span> <span class="k">struct</span> <span class="n">task_struct</span> <span class="o">*</span><span class="n">tsk</span><span class="p">)</span>
</span></span><span class="line"><span class="ln"> 3</span><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="ln"> 4</span><span class="cl">    <span class="k">struct</span> <span class="n">sighand_struct</span> <span class="o">*</span><span class="n">sig</span><span class="p">;</span>
</span></span><span class="line"><span class="ln"> 5</span><span class="cl">
</span></span><span class="line"><span class="ln"> 6</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="n">clone_flags</span> <span class="o">&amp;</span> <span class="n">CLONE_SIGHAND</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln"> 7</span><span class="cl">        <span class="nf">refcount_inc</span><span class="p">(</span><span class="o">&amp;</span><span class="n">current</span><span class="o">-&gt;</span><span class="n">sighand</span><span class="o">-&gt;</span><span class="n">count</span><span class="p">);</span>
</span></span><span class="line"><span class="ln"> 8</span><span class="cl">        <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="ln"> 9</span><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="ln">10</span><span class="cl">    <span class="n">sig</span> <span class="o">=</span> <span class="nf">kmem_cache_alloc</span><span class="p">(</span><span class="n">sighand_cachep</span><span class="p">,</span> <span class="n">GFP_KERNEL</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">11</span><span class="cl">    <span class="nf">RCU_INIT_POINTER</span><span class="p">(</span><span class="n">tsk</span><span class="o">-&gt;</span><span class="n">sighand</span><span class="p">,</span> <span class="n">sig</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">12</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">sig</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">13</span><span class="cl">        <span class="k">return</span> <span class="o">-</span><span class="n">ENOMEM</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">14</span><span class="cl">
</span></span><span class="line"><span class="ln">15</span><span class="cl">    <span class="nf">refcount_set</span><span class="p">(</span><span class="o">&amp;</span><span class="n">sig</span><span class="o">-&gt;</span><span class="n">count</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">16</span><span class="cl">    <span class="nf">spin_lock_irq</span><span class="p">(</span><span class="o">&amp;</span><span class="n">current</span><span class="o">-&gt;</span><span class="n">sighand</span><span class="o">-&gt;</span><span class="n">siglock</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">17</span><span class="cl">    <span class="nf">memcpy</span><span class="p">(</span><span class="n">sig</span><span class="o">-&gt;</span><span class="n">action</span><span class="p">,</span> <span class="n">current</span><span class="o">-&gt;</span><span class="n">sighand</span><span class="o">-&gt;</span><span class="n">action</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">sig</span><span class="o">-&gt;</span><span class="n">action</span><span class="p">));</span>
</span></span><span class="line"><span class="ln">18</span><span class="cl">    <span class="nf">spin_unlock_irq</span><span class="p">(</span><span class="o">&amp;</span><span class="n">current</span><span class="o">-&gt;</span><span class="n">sighand</span><span class="o">-&gt;</span><span class="n">siglock</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">19</span><span class="cl">
</span></span><span class="line"><span class="ln">20</span><span class="cl">    <span class="cm">/* Reset all signal handler not set to SIG_IGN to SIG_DFL. */</span>
</span></span><span class="line"><span class="ln">21</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="n">clone_flags</span> <span class="o">&amp;</span> <span class="n">CLONE_CLEAR_SIGHAND</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">22</span><span class="cl">        <span class="nf">flush_signal_handlers</span><span class="p">(</span><span class="n">tsk</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">23</span><span class="cl">
</span></span><span class="line"><span class="ln">24</span><span class="cl">    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">25</span><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><h1 id="7-copy_signal">7. copy_signal</h1>
<p>如果clone_flags包含CLONE_THREAD，也就是创建线程，不做任何操作。否则，创建新的signal，并初始化各个变量。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln">1</span><span class="cl">    <span class="n">retval</span> <span class="o">=</span> <span class="nf">copy_signal</span><span class="p">(</span><span class="n">clone_flags</span><span class="p">,</span> <span class="n">p</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">2</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="n">retval</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">3</span><span class="cl">        <span class="k">goto</span> <span class="n">bad_fork_cleanup_sighand</span><span class="p">;</span>
</span></span></code></pre></div><h2 id="71-copy_signal源码">7.1. copy_signal源码</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln"> 1</span><span class="cl"><span class="c1">/// kernel/fork.c
</span></span></span><span class="line"><span class="ln"> 2</span><span class="cl"><span class="c1"></span><span class="k">static</span> <span class="kt">int</span> <span class="nf">copy_signal</span><span class="p">(</span><span class="kt">unsigned</span> <span class="kt">long</span> <span class="n">clone_flags</span><span class="p">,</span> <span class="k">struct</span> <span class="n">task_struct</span> <span class="o">*</span><span class="n">tsk</span><span class="p">)</span>
</span></span><span class="line"><span class="ln"> 3</span><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="ln"> 4</span><span class="cl">    <span class="k">struct</span> <span class="n">signal_struct</span> <span class="o">*</span><span class="n">sig</span><span class="p">;</span>
</span></span><span class="line"><span class="ln"> 5</span><span class="cl">
</span></span><span class="line"><span class="ln"> 6</span><span class="cl">    <span class="c1">/// 如果是创建线程，则不做任何操作
</span></span></span><span class="line"><span class="ln"> 7</span><span class="cl"><span class="c1"></span>    <span class="k">if</span> <span class="p">(</span><span class="n">clone_flags</span> <span class="o">&amp;</span> <span class="n">CLONE_THREAD</span><span class="p">)</span>
</span></span><span class="line"><span class="ln"> 8</span><span class="cl">        <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="ln"> 9</span><span class="cl">
</span></span><span class="line"><span class="ln">10</span><span class="cl">    <span class="n">sig</span> <span class="o">=</span> <span class="nf">kmem_cache_zalloc</span><span class="p">(</span><span class="n">signal_cachep</span><span class="p">,</span> <span class="n">GFP_KERNEL</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">11</span><span class="cl">    <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">signal</span> <span class="o">=</span> <span class="n">sig</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">12</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">sig</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">13</span><span class="cl">        <span class="k">return</span> <span class="o">-</span><span class="n">ENOMEM</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">14</span><span class="cl">
</span></span><span class="line"><span class="ln">15</span><span class="cl">    <span class="c1">/// 新进程默认计数为1
</span></span></span><span class="line"><span class="ln">16</span><span class="cl"><span class="c1"></span>    <span class="n">sig</span><span class="o">-&gt;</span><span class="n">nr_threads</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">17</span><span class="cl">    <span class="n">sig</span><span class="o">-&gt;</span><span class="n">quick_threads</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">18</span><span class="cl">    <span class="nf">atomic_set</span><span class="p">(</span><span class="o">&amp;</span><span class="n">sig</span><span class="o">-&gt;</span><span class="n">live</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">19</span><span class="cl">    <span class="nf">refcount_set</span><span class="p">(</span><span class="o">&amp;</span><span class="n">sig</span><span class="o">-&gt;</span><span class="n">sigcnt</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">20</span><span class="cl">
</span></span><span class="line"><span class="ln">21</span><span class="cl">    <span class="c1">/// 快速将tsk和sig的list关联起来
</span></span></span><span class="line"><span class="ln">22</span><span class="cl"><span class="c1"></span>    <span class="cm">/* list_add(thread_node, thread_head) without INIT_LIST_HEAD() */</span>
</span></span><span class="line"><span class="ln">23</span><span class="cl">    <span class="n">sig</span><span class="o">-&gt;</span><span class="n">thread_head</span> <span class="o">=</span> <span class="p">(</span><span class="k">struct</span> <span class="n">list_head</span><span class="p">)</span><span class="nf">LIST_HEAD_INIT</span><span class="p">(</span><span class="n">tsk</span><span class="o">-&gt;</span><span class="n">thread_node</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">24</span><span class="cl">    <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">thread_node</span> <span class="o">=</span> <span class="p">(</span><span class="k">struct</span> <span class="n">list_head</span><span class="p">)</span><span class="nf">LIST_HEAD_INIT</span><span class="p">(</span><span class="n">sig</span><span class="o">-&gt;</span><span class="n">thread_head</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">25</span><span class="cl">
</span></span><span class="line"><span class="ln">26</span><span class="cl">    <span class="nf">init_waitqueue_head</span><span class="p">(</span><span class="o">&amp;</span><span class="n">sig</span><span class="o">-&gt;</span><span class="n">wait_chldexit</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">27</span><span class="cl">    <span class="n">sig</span><span class="o">-&gt;</span><span class="n">curr_target</span> <span class="o">=</span> <span class="n">tsk</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">28</span><span class="cl">    <span class="nf">init_sigpending</span><span class="p">(</span><span class="o">&amp;</span><span class="n">sig</span><span class="o">-&gt;</span><span class="n">shared_pending</span><span class="p">);</span>      <span class="c1">/// 清空signal
</span></span></span><span class="line"><span class="ln">29</span><span class="cl"><span class="c1"></span>    <span class="nf">INIT_HLIST_HEAD</span><span class="p">(</span><span class="o">&amp;</span><span class="n">sig</span><span class="o">-&gt;</span><span class="n">multiprocess</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">30</span><span class="cl">    <span class="nf">seqlock_init</span><span class="p">(</span><span class="o">&amp;</span><span class="n">sig</span><span class="o">-&gt;</span><span class="n">stats_lock</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">31</span><span class="cl">    <span class="nf">prev_cputime_init</span><span class="p">(</span><span class="o">&amp;</span><span class="n">sig</span><span class="o">-&gt;</span><span class="n">prev_cputime</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">32</span><span class="cl">
</span></span><span class="line"><span class="ln">33</span><span class="cl"><span class="cp">#ifdef CONFIG_POSIX_TIMERS
</span></span></span><span class="line"><span class="ln">34</span><span class="cl"><span class="cp"></span>    <span class="nf">INIT_LIST_HEAD</span><span class="p">(</span><span class="o">&amp;</span><span class="n">sig</span><span class="o">-&gt;</span><span class="n">posix_timers</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">35</span><span class="cl">    <span class="nf">hrtimer_init</span><span class="p">(</span><span class="o">&amp;</span><span class="n">sig</span><span class="o">-&gt;</span><span class="n">real_timer</span><span class="p">,</span> <span class="n">CLOCK_MONOTONIC</span><span class="p">,</span> <span class="n">HRTIMER_MODE_REL</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">36</span><span class="cl">    <span class="n">sig</span><span class="o">-&gt;</span><span class="n">real_timer</span><span class="p">.</span><span class="n">function</span> <span class="o">=</span> <span class="n">it_real_fn</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">37</span><span class="cl"><span class="cp">#endif
</span></span></span><span class="line"><span class="ln">38</span><span class="cl"><span class="cp"></span>
</span></span><span class="line"><span class="ln">39</span><span class="cl">    <span class="c1">/// 复制父进程的rlim，fork可能是父进程的子线程调用的，这里用group_leader找到主线程
</span></span></span><span class="line"><span class="ln">40</span><span class="cl"><span class="c1"></span>    <span class="nf">task_lock</span><span class="p">(</span><span class="n">current</span><span class="o">-&gt;</span><span class="n">group_leader</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">41</span><span class="cl">    <span class="nf">memcpy</span><span class="p">(</span><span class="n">sig</span><span class="o">-&gt;</span><span class="n">rlim</span><span class="p">,</span> <span class="n">current</span><span class="o">-&gt;</span><span class="n">signal</span><span class="o">-&gt;</span><span class="n">rlim</span><span class="p">,</span> <span class="k">sizeof</span> <span class="n">sig</span><span class="o">-&gt;</span><span class="n">rlim</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">42</span><span class="cl">    <span class="nf">task_unlock</span><span class="p">(</span><span class="n">current</span><span class="o">-&gt;</span><span class="n">group_leader</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">43</span><span class="cl">
</span></span><span class="line"><span class="ln">44</span><span class="cl">    <span class="nf">posix_cpu_timers_init_group</span><span class="p">(</span><span class="n">sig</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">45</span><span class="cl">
</span></span><span class="line"><span class="ln">46</span><span class="cl">    <span class="nf">tty_audit_fork</span><span class="p">(</span><span class="n">sig</span><span class="p">);</span>        <span class="c1">/// 审计日志
</span></span></span><span class="line"><span class="ln">47</span><span class="cl"><span class="c1"></span>    <span class="nf">sched_autogroup_fork</span><span class="p">(</span><span class="n">sig</span><span class="p">);</span>  <span class="c1">/// 增加当前调度组引用计数
</span></span></span><span class="line"><span class="ln">48</span><span class="cl"><span class="c1"></span>
</span></span><span class="line"><span class="ln">49</span><span class="cl">    <span class="c1">/// 复制oom信息
</span></span></span><span class="line"><span class="ln">50</span><span class="cl"><span class="c1"></span>    <span class="n">sig</span><span class="o">-&gt;</span><span class="n">oom_score_adj</span> <span class="o">=</span> <span class="n">current</span><span class="o">-&gt;</span><span class="n">signal</span><span class="o">-&gt;</span><span class="n">oom_score_adj</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">51</span><span class="cl">    <span class="n">sig</span><span class="o">-&gt;</span><span class="n">oom_score_adj_min</span> <span class="o">=</span> <span class="n">current</span><span class="o">-&gt;</span><span class="n">signal</span><span class="o">-&gt;</span><span class="n">oom_score_adj_min</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">52</span><span class="cl">
</span></span><span class="line"><span class="ln">53</span><span class="cl">    <span class="nf">mutex_init</span><span class="p">(</span><span class="o">&amp;</span><span class="n">sig</span><span class="o">-&gt;</span><span class="n">cred_guard_mutex</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">54</span><span class="cl">    <span class="nf">init_rwsem</span><span class="p">(</span><span class="o">&amp;</span><span class="n">sig</span><span class="o">-&gt;</span><span class="n">exec_update_lock</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">55</span><span class="cl">
</span></span><span class="line"><span class="ln">56</span><span class="cl">    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">57</span><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><h1 id="8-copy_mm">8. copy_mm</h1>
<p>如果父进程是用户程序，且clone_flags包含CLONE_VM，则共享父进程mm_struct。否则调用dup_mm复制父进程的mm_struct。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln">1</span><span class="cl">    <span class="n">retval</span> <span class="o">=</span> <span class="nf">copy_mm</span><span class="p">(</span><span class="n">clone_flags</span><span class="p">,</span> <span class="n">p</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">2</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="n">retval</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">3</span><span class="cl">        <span class="k">goto</span> <span class="n">bad_fork_cleanup_signal</span><span class="p">;</span>
</span></span></code></pre></div><h2 id="81-copy_mm源码">8.1. copy_mm源码</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln"> 1</span><span class="cl"><span class="c1">/// kernel/fork.c
</span></span></span><span class="line"><span class="ln"> 2</span><span class="cl"><span class="c1"></span><span class="k">static</span> <span class="kt">int</span> <span class="nf">copy_mm</span><span class="p">(</span><span class="kt">unsigned</span> <span class="kt">long</span> <span class="n">clone_flags</span><span class="p">,</span> <span class="k">struct</span> <span class="n">task_struct</span> <span class="o">*</span><span class="n">tsk</span><span class="p">)</span>
</span></span><span class="line"><span class="ln"> 3</span><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="ln"> 4</span><span class="cl">    <span class="k">struct</span> <span class="n">mm_struct</span> <span class="o">*</span><span class="n">mm</span><span class="p">,</span> <span class="o">*</span><span class="n">oldmm</span><span class="p">;</span>
</span></span><span class="line"><span class="ln"> 5</span><span class="cl">
</span></span><span class="line"><span class="ln"> 6</span><span class="cl">    <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">min_flt</span> <span class="o">=</span> <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">maj_flt</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="ln"> 7</span><span class="cl">    <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">nvcsw</span> <span class="o">=</span> <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">nivcsw</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="ln"> 8</span><span class="cl"><span class="cp">#ifdef CONFIG_DETECT_HUNG_TASK
</span></span></span><span class="line"><span class="ln"> 9</span><span class="cl"><span class="cp"></span>    <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">last_switch_count</span> <span class="o">=</span> <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">nvcsw</span> <span class="o">+</span> <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">nivcsw</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">10</span><span class="cl">    <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">last_switch_time</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">11</span><span class="cl"><span class="cp">#endif
</span></span></span><span class="line"><span class="ln">12</span><span class="cl"><span class="cp"></span>
</span></span><span class="line"><span class="ln">13</span><span class="cl">    <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">mm</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">14</span><span class="cl">    <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">active_mm</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">15</span><span class="cl">
</span></span><span class="line"><span class="ln">16</span><span class="cl">    <span class="cm">/*
</span></span></span><span class="line"><span class="ln">17</span><span class="cl"><span class="cm">     * Are we cloning a kernel thread?
</span></span></span><span class="line"><span class="ln">18</span><span class="cl"><span class="cm">     *
</span></span></span><span class="line"><span class="ln">19</span><span class="cl"><span class="cm">     * We need to steal a active VM for that..
</span></span></span><span class="line"><span class="ln">20</span><span class="cl"><span class="cm">     */</span>
</span></span><span class="line"><span class="ln">21</span><span class="cl">    <span class="n">oldmm</span> <span class="o">=</span> <span class="n">current</span><span class="o">-&gt;</span><span class="n">mm</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">22</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">oldmm</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">23</span><span class="cl">        <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">24</span><span class="cl">
</span></span><span class="line"><span class="ln">25</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="n">clone_flags</span> <span class="o">&amp;</span> <span class="n">CLONE_VM</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln">26</span><span class="cl">        <span class="nf">mmget</span><span class="p">(</span><span class="n">oldmm</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">27</span><span class="cl">        <span class="n">mm</span> <span class="o">=</span> <span class="n">oldmm</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">28</span><span class="cl">    <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln">29</span><span class="cl">        <span class="n">mm</span> <span class="o">=</span> <span class="nf">dup_mm</span><span class="p">(</span><span class="n">tsk</span><span class="p">,</span> <span class="n">current</span><span class="o">-&gt;</span><span class="n">mm</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">30</span><span class="cl">        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">mm</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">31</span><span class="cl">            <span class="k">return</span> <span class="o">-</span><span class="n">ENOMEM</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">32</span><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="ln">33</span><span class="cl">
</span></span><span class="line"><span class="ln">34</span><span class="cl">    <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">mm</span> <span class="o">=</span> <span class="n">mm</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">35</span><span class="cl">    <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">active_mm</span> <span class="o">=</span> <span class="n">mm</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">36</span><span class="cl">    <span class="nf">sched_mm_cid_fork</span><span class="p">(</span><span class="n">tsk</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">37</span><span class="cl">    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">38</span><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><h1 id="9-copy_namespaces">9. copy_namespaces</h1>
<p>copy_namespaces共享或创建新的除user namespace之外的namespace。
检查是否需要创建新的命名空间，如果不需要，增加父进程命名空间的引用计数。如果需要创建新的命名空间，还需要检查是否有管理员权限。之后就是调用create_new_namespaces来完成新的命名空间创建。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln">1</span><span class="cl">    <span class="n">retval</span> <span class="o">=</span> <span class="nf">copy_namespaces</span><span class="p">(</span><span class="n">clone_flags</span><span class="p">,</span> <span class="n">p</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">2</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="n">retval</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">3</span><span class="cl">        <span class="k">goto</span> <span class="n">bad_fork_cleanup_mm</span><span class="p">;</span>
</span></span></code></pre></div><h2 id="91-copy_namespaces源码">9.1. copy_namespaces源码</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln"> 1</span><span class="cl"><span class="c1">/// kernel/nsproxy.c
</span></span></span><span class="line"><span class="ln"> 2</span><span class="cl"><span class="c1"></span><span class="cm">/*
</span></span></span><span class="line"><span class="ln"> 3</span><span class="cl"><span class="cm"> * called from clone.  This now handles copy for nsproxy and all
</span></span></span><span class="line"><span class="ln"> 4</span><span class="cl"><span class="cm"> * namespaces therein.
</span></span></span><span class="line"><span class="ln"> 5</span><span class="cl"><span class="cm"> */</span>
</span></span><span class="line"><span class="ln"> 6</span><span class="cl"><span class="kt">int</span> <span class="nf">copy_namespaces</span><span class="p">(</span><span class="kt">unsigned</span> <span class="kt">long</span> <span class="n">flags</span><span class="p">,</span> <span class="k">struct</span> <span class="n">task_struct</span> <span class="o">*</span><span class="n">tsk</span><span class="p">)</span>
</span></span><span class="line"><span class="ln"> 7</span><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="ln"> 8</span><span class="cl">    <span class="k">struct</span> <span class="n">nsproxy</span> <span class="o">*</span><span class="n">old_ns</span> <span class="o">=</span> <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">nsproxy</span><span class="p">;</span>
</span></span><span class="line"><span class="ln"> 9</span><span class="cl">    <span class="k">struct</span> <span class="n">user_namespace</span> <span class="o">*</span><span class="n">user_ns</span> <span class="o">=</span> <span class="nf">task_cred_xxx</span><span class="p">(</span><span class="n">tsk</span><span class="p">,</span> <span class="n">user_ns</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">10</span><span class="cl">    <span class="k">struct</span> <span class="n">nsproxy</span> <span class="o">*</span><span class="n">new_ns</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">11</span><span class="cl">
</span></span><span class="line"><span class="ln">12</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="nf">likely</span><span class="p">(</span><span class="o">!</span><span class="p">(</span><span class="n">flags</span> <span class="o">&amp;</span> <span class="p">(</span><span class="n">CLONE_NEWNS</span> <span class="o">|</span> <span class="n">CLONE_NEWUTS</span> <span class="o">|</span> <span class="n">CLONE_NEWIPC</span> <span class="o">|</span>
</span></span><span class="line"><span class="ln">13</span><span class="cl">                  <span class="n">CLONE_NEWPID</span> <span class="o">|</span> <span class="n">CLONE_NEWNET</span> <span class="o">|</span>
</span></span><span class="line"><span class="ln">14</span><span class="cl">                  <span class="n">CLONE_NEWCGROUP</span> <span class="o">|</span> <span class="n">CLONE_NEWTIME</span><span class="p">))))</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln">15</span><span class="cl">        <span class="k">if</span> <span class="p">((</span><span class="n">flags</span> <span class="o">&amp;</span> <span class="n">CLONE_VM</span><span class="p">)</span> <span class="o">||</span>
</span></span><span class="line"><span class="ln">16</span><span class="cl">            <span class="nf">likely</span><span class="p">(</span><span class="n">old_ns</span><span class="o">-&gt;</span><span class="n">time_ns_for_children</span> <span class="o">==</span> <span class="n">old_ns</span><span class="o">-&gt;</span><span class="n">time_ns</span><span class="p">))</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln">17</span><span class="cl">            <span class="nf">get_nsproxy</span><span class="p">(</span><span class="n">old_ns</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">18</span><span class="cl">            <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">19</span><span class="cl">        <span class="p">}</span>
</span></span><span class="line"><span class="ln">20</span><span class="cl">    <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nf">ns_capable</span><span class="p">(</span><span class="n">user_ns</span><span class="p">,</span> <span class="n">CAP_SYS_ADMIN</span><span class="p">))</span>
</span></span><span class="line"><span class="ln">21</span><span class="cl">        <span class="k">return</span> <span class="o">-</span><span class="n">EPERM</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">22</span><span class="cl">
</span></span><span class="line"><span class="ln">23</span><span class="cl">    <span class="cm">/*
</span></span></span><span class="line"><span class="ln">24</span><span class="cl"><span class="cm">     * CLONE_NEWIPC must detach from the undolist: after switching
</span></span></span><span class="line"><span class="ln">25</span><span class="cl"><span class="cm">     * to a new ipc namespace, the semaphore arrays from the old
</span></span></span><span class="line"><span class="ln">26</span><span class="cl"><span class="cm">     * namespace are unreachable.  In clone parlance, CLONE_SYSVSEM
</span></span></span><span class="line"><span class="ln">27</span><span class="cl"><span class="cm">     * means share undolist with parent, so we must forbid using
</span></span></span><span class="line"><span class="ln">28</span><span class="cl"><span class="cm">     * it along with CLONE_NEWIPC.
</span></span></span><span class="line"><span class="ln">29</span><span class="cl"><span class="cm">     */</span>
</span></span><span class="line"><span class="ln">30</span><span class="cl">    <span class="k">if</span> <span class="p">((</span><span class="n">flags</span> <span class="o">&amp;</span> <span class="p">(</span><span class="n">CLONE_NEWIPC</span> <span class="o">|</span> <span class="n">CLONE_SYSVSEM</span><span class="p">))</span> <span class="o">==</span>
</span></span><span class="line"><span class="ln">31</span><span class="cl">        <span class="p">(</span><span class="n">CLONE_NEWIPC</span> <span class="o">|</span> <span class="n">CLONE_SYSVSEM</span><span class="p">))</span>
</span></span><span class="line"><span class="ln">32</span><span class="cl">        <span class="k">return</span> <span class="o">-</span><span class="n">EINVAL</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">33</span><span class="cl">
</span></span><span class="line"><span class="ln">34</span><span class="cl">    <span class="n">new_ns</span> <span class="o">=</span> <span class="nf">create_new_namespaces</span><span class="p">(</span><span class="n">flags</span><span class="p">,</span> <span class="n">tsk</span><span class="p">,</span> <span class="n">user_ns</span><span class="p">,</span> <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">fs</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">35</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="nf">IS_ERR</span><span class="p">(</span><span class="n">new_ns</span><span class="p">))</span>
</span></span><span class="line"><span class="ln">36</span><span class="cl">        <span class="k">return</span>  <span class="nf">PTR_ERR</span><span class="p">(</span><span class="n">new_ns</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">37</span><span class="cl">
</span></span><span class="line"><span class="ln">38</span><span class="cl">    <span class="k">if</span> <span class="p">((</span><span class="n">flags</span> <span class="o">&amp;</span> <span class="n">CLONE_VM</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">39</span><span class="cl">        <span class="nf">timens_on_fork</span><span class="p">(</span><span class="n">new_ns</span><span class="p">,</span> <span class="n">tsk</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">40</span><span class="cl">
</span></span><span class="line"><span class="ln">41</span><span class="cl">    <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">nsproxy</span> <span class="o">=</span> <span class="n">new_ns</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">42</span><span class="cl">    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">43</span><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><h2 id="92-create_new_namespaces源码">9.2. create_new_namespaces源码</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln"> 1</span><span class="cl"><span class="c1">/// kernel/nsproxy.c
</span></span></span><span class="line"><span class="ln"> 2</span><span class="cl"><span class="c1"></span><span class="cm">/*
</span></span></span><span class="line"><span class="ln"> 3</span><span class="cl"><span class="cm"> * Create new nsproxy and all of its the associated namespaces.
</span></span></span><span class="line"><span class="ln"> 4</span><span class="cl"><span class="cm"> * Return the newly created nsproxy.  Do not attach this to the task,
</span></span></span><span class="line"><span class="ln"> 5</span><span class="cl"><span class="cm"> * leave it to the caller to do proper locking and attach it to task.
</span></span></span><span class="line"><span class="ln"> 6</span><span class="cl"><span class="cm"> */</span>
</span></span><span class="line"><span class="ln"> 7</span><span class="cl"><span class="k">static</span> <span class="k">struct</span> <span class="n">nsproxy</span> <span class="o">*</span><span class="nf">create_new_namespaces</span><span class="p">(</span><span class="kt">unsigned</span> <span class="kt">long</span> <span class="n">flags</span><span class="p">,</span>
</span></span><span class="line"><span class="ln"> 8</span><span class="cl">    <span class="k">struct</span> <span class="n">task_struct</span> <span class="o">*</span><span class="n">tsk</span><span class="p">,</span> <span class="k">struct</span> <span class="n">user_namespace</span> <span class="o">*</span><span class="n">user_ns</span><span class="p">,</span>
</span></span><span class="line"><span class="ln"> 9</span><span class="cl">    <span class="k">struct</span> <span class="n">fs_struct</span> <span class="o">*</span><span class="n">new_fs</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">10</span><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="ln">11</span><span class="cl">    <span class="k">struct</span> <span class="n">nsproxy</span> <span class="o">*</span><span class="n">new_nsp</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">12</span><span class="cl">    <span class="kt">int</span> <span class="n">err</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">13</span><span class="cl">
</span></span><span class="line"><span class="ln">14</span><span class="cl">    <span class="n">new_nsp</span> <span class="o">=</span> <span class="nf">create_nsproxy</span><span class="p">();</span>
</span></span><span class="line"><span class="ln">15</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">new_nsp</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">16</span><span class="cl">        <span class="k">return</span> <span class="nf">ERR_PTR</span><span class="p">(</span><span class="o">-</span><span class="n">ENOMEM</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">17</span><span class="cl">
</span></span><span class="line"><span class="ln">18</span><span class="cl">    <span class="n">new_nsp</span><span class="o">-&gt;</span><span class="n">mnt_ns</span> <span class="o">=</span> <span class="nf">copy_mnt_ns</span><span class="p">(</span><span class="n">flags</span><span class="p">,</span> <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">nsproxy</span><span class="o">-&gt;</span><span class="n">mnt_ns</span><span class="p">,</span> <span class="n">user_ns</span><span class="p">,</span> <span class="n">new_fs</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">19</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="nf">IS_ERR</span><span class="p">(</span><span class="n">new_nsp</span><span class="o">-&gt;</span><span class="n">mnt_ns</span><span class="p">))</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln">20</span><span class="cl">        <span class="n">err</span> <span class="o">=</span> <span class="nf">PTR_ERR</span><span class="p">(</span><span class="n">new_nsp</span><span class="o">-&gt;</span><span class="n">mnt_ns</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">21</span><span class="cl">        <span class="k">goto</span> <span class="n">out_ns</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">22</span><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="ln">23</span><span class="cl">
</span></span><span class="line"><span class="ln">24</span><span class="cl">    <span class="n">new_nsp</span><span class="o">-&gt;</span><span class="n">uts_ns</span> <span class="o">=</span> <span class="nf">copy_utsname</span><span class="p">(</span><span class="n">flags</span><span class="p">,</span> <span class="n">user_ns</span><span class="p">,</span> <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">nsproxy</span><span class="o">-&gt;</span><span class="n">uts_ns</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">25</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="nf">IS_ERR</span><span class="p">(</span><span class="n">new_nsp</span><span class="o">-&gt;</span><span class="n">uts_ns</span><span class="p">))</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln">26</span><span class="cl">        <span class="n">err</span> <span class="o">=</span> <span class="nf">PTR_ERR</span><span class="p">(</span><span class="n">new_nsp</span><span class="o">-&gt;</span><span class="n">uts_ns</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">27</span><span class="cl">        <span class="k">goto</span> <span class="n">out_uts</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">28</span><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="ln">29</span><span class="cl">
</span></span><span class="line"><span class="ln">30</span><span class="cl">    <span class="n">new_nsp</span><span class="o">-&gt;</span><span class="n">ipc_ns</span> <span class="o">=</span> <span class="nf">copy_ipcs</span><span class="p">(</span><span class="n">flags</span><span class="p">,</span> <span class="n">user_ns</span><span class="p">,</span> <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">nsproxy</span><span class="o">-&gt;</span><span class="n">ipc_ns</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">31</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="nf">IS_ERR</span><span class="p">(</span><span class="n">new_nsp</span><span class="o">-&gt;</span><span class="n">ipc_ns</span><span class="p">))</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln">32</span><span class="cl">        <span class="n">err</span> <span class="o">=</span> <span class="nf">PTR_ERR</span><span class="p">(</span><span class="n">new_nsp</span><span class="o">-&gt;</span><span class="n">ipc_ns</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">33</span><span class="cl">        <span class="k">goto</span> <span class="n">out_ipc</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">34</span><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="ln">35</span><span class="cl">
</span></span><span class="line"><span class="ln">36</span><span class="cl">    <span class="n">new_nsp</span><span class="o">-&gt;</span><span class="n">pid_ns_for_children</span> <span class="o">=</span>
</span></span><span class="line"><span class="ln">37</span><span class="cl">        <span class="nf">copy_pid_ns</span><span class="p">(</span><span class="n">flags</span><span class="p">,</span> <span class="n">user_ns</span><span class="p">,</span> <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">nsproxy</span><span class="o">-&gt;</span><span class="n">pid_ns_for_children</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">38</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="nf">IS_ERR</span><span class="p">(</span><span class="n">new_nsp</span><span class="o">-&gt;</span><span class="n">pid_ns_for_children</span><span class="p">))</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln">39</span><span class="cl">        <span class="n">err</span> <span class="o">=</span> <span class="nf">PTR_ERR</span><span class="p">(</span><span class="n">new_nsp</span><span class="o">-&gt;</span><span class="n">pid_ns_for_children</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">40</span><span class="cl">        <span class="k">goto</span> <span class="n">out_pid</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">41</span><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="ln">42</span><span class="cl">
</span></span><span class="line"><span class="ln">43</span><span class="cl">    <span class="n">new_nsp</span><span class="o">-&gt;</span><span class="n">cgroup_ns</span> <span class="o">=</span> <span class="nf">copy_cgroup_ns</span><span class="p">(</span><span class="n">flags</span><span class="p">,</span> <span class="n">user_ns</span><span class="p">,</span>
</span></span><span class="line"><span class="ln">44</span><span class="cl">                        <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">nsproxy</span><span class="o">-&gt;</span><span class="n">cgroup_ns</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">45</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="nf">IS_ERR</span><span class="p">(</span><span class="n">new_nsp</span><span class="o">-&gt;</span><span class="n">cgroup_ns</span><span class="p">))</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln">46</span><span class="cl">        <span class="n">err</span> <span class="o">=</span> <span class="nf">PTR_ERR</span><span class="p">(</span><span class="n">new_nsp</span><span class="o">-&gt;</span><span class="n">cgroup_ns</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">47</span><span class="cl">        <span class="k">goto</span> <span class="n">out_cgroup</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">48</span><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="ln">49</span><span class="cl">
</span></span><span class="line"><span class="ln">50</span><span class="cl">    <span class="n">new_nsp</span><span class="o">-&gt;</span><span class="n">net_ns</span> <span class="o">=</span> <span class="nf">copy_net_ns</span><span class="p">(</span><span class="n">flags</span><span class="p">,</span> <span class="n">user_ns</span><span class="p">,</span> <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">nsproxy</span><span class="o">-&gt;</span><span class="n">net_ns</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">51</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="nf">IS_ERR</span><span class="p">(</span><span class="n">new_nsp</span><span class="o">-&gt;</span><span class="n">net_ns</span><span class="p">))</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln">52</span><span class="cl">        <span class="n">err</span> <span class="o">=</span> <span class="nf">PTR_ERR</span><span class="p">(</span><span class="n">new_nsp</span><span class="o">-&gt;</span><span class="n">net_ns</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">53</span><span class="cl">        <span class="k">goto</span> <span class="n">out_net</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">54</span><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="ln">55</span><span class="cl">
</span></span><span class="line"><span class="ln">56</span><span class="cl">    <span class="n">new_nsp</span><span class="o">-&gt;</span><span class="n">time_ns_for_children</span> <span class="o">=</span> <span class="nf">copy_time_ns</span><span class="p">(</span><span class="n">flags</span><span class="p">,</span> <span class="n">user_ns</span><span class="p">,</span>
</span></span><span class="line"><span class="ln">57</span><span class="cl">                    <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">nsproxy</span><span class="o">-&gt;</span><span class="n">time_ns_for_children</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">58</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="nf">IS_ERR</span><span class="p">(</span><span class="n">new_nsp</span><span class="o">-&gt;</span><span class="n">time_ns_for_children</span><span class="p">))</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln">59</span><span class="cl">        <span class="n">err</span> <span class="o">=</span> <span class="nf">PTR_ERR</span><span class="p">(</span><span class="n">new_nsp</span><span class="o">-&gt;</span><span class="n">time_ns_for_children</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">60</span><span class="cl">        <span class="k">goto</span> <span class="n">out_time</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">61</span><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="ln">62</span><span class="cl">    <span class="n">new_nsp</span><span class="o">-&gt;</span><span class="n">time_ns</span> <span class="o">=</span> <span class="nf">get_time_ns</span><span class="p">(</span><span class="n">tsk</span><span class="o">-&gt;</span><span class="n">nsproxy</span><span class="o">-&gt;</span><span class="n">time_ns</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">63</span><span class="cl">
</span></span><span class="line"><span class="ln">64</span><span class="cl">    <span class="k">return</span> <span class="n">new_nsp</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">65</span><span class="cl">    <span class="c1">/// ... ...
</span></span></span><span class="line"><span class="ln">66</span><span class="cl"><span class="c1"></span><span class="p">}</span>
</span></span></code></pre></div><h2 id="93-timens_on_fork">9.3. timens_on_fork</h2>
<p>在新进程不与父进程共享vm的情况下调用，这个时候新进程也不共享父进程的命名空间（time_ns成员）。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln"> 1</span><span class="cl"><span class="c1">/// kernel/time/namespace.c
</span></span></span><span class="line"><span class="ln"> 2</span><span class="cl"><span class="c1"></span><span class="kt">void</span> <span class="nf">timens_on_fork</span><span class="p">(</span><span class="k">struct</span> <span class="n">nsproxy</span> <span class="o">*</span><span class="n">nsproxy</span><span class="p">,</span> <span class="k">struct</span> <span class="n">task_struct</span> <span class="o">*</span><span class="n">tsk</span><span class="p">)</span>
</span></span><span class="line"><span class="ln"> 3</span><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="ln"> 4</span><span class="cl">    <span class="k">struct</span> <span class="n">ns_common</span> <span class="o">*</span><span class="n">nsc</span> <span class="o">=</span> <span class="o">&amp;</span><span class="n">nsproxy</span><span class="o">-&gt;</span><span class="n">time_ns_for_children</span><span class="o">-&gt;</span><span class="n">ns</span><span class="p">;</span>
</span></span><span class="line"><span class="ln"> 5</span><span class="cl">    <span class="k">struct</span> <span class="n">time_namespace</span> <span class="o">*</span><span class="n">ns</span> <span class="o">=</span> <span class="nf">to_time_ns</span><span class="p">(</span><span class="n">nsc</span><span class="p">);</span>
</span></span><span class="line"><span class="ln"> 6</span><span class="cl">
</span></span><span class="line"><span class="ln"> 7</span><span class="cl">    <span class="c1">/// init_task的time_ns和time_ns_for_children是同一个
</span></span></span><span class="line"><span class="ln"> 8</span><span class="cl"><span class="c1"></span>    <span class="c1">/// fork时如果创建了新的timens，这里time_ns_for_children是新的
</span></span></span><span class="line"><span class="ln"> 9</span><span class="cl"><span class="c1"></span>    <span class="c1">/// 而time_ns还与父进程的time_ns保持一致
</span></span></span><span class="line"><span class="ln">10</span><span class="cl"><span class="c1"></span>    <span class="cm">/* create_new_namespaces() already incremented the ref counter */</span>
</span></span><span class="line"><span class="ln">11</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="n">nsproxy</span><span class="o">-&gt;</span><span class="n">time_ns</span> <span class="o">==</span> <span class="n">nsproxy</span><span class="o">-&gt;</span><span class="n">time_ns_for_children</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">12</span><span class="cl">        <span class="k">return</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">13</span><span class="cl">
</span></span><span class="line"><span class="ln">14</span><span class="cl">    <span class="nf">get_time_ns</span><span class="p">(</span><span class="n">ns</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">15</span><span class="cl">    <span class="nf">put_time_ns</span><span class="p">(</span><span class="n">nsproxy</span><span class="o">-&gt;</span><span class="n">time_ns</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">16</span><span class="cl">    <span class="c1">/// 使新进程的time_ns和time_ns_for_children相同
</span></span></span><span class="line"><span class="ln">17</span><span class="cl"><span class="c1"></span>    <span class="n">nsproxy</span><span class="o">-&gt;</span><span class="n">time_ns</span> <span class="o">=</span> <span class="n">ns</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">18</span><span class="cl">
</span></span><span class="line"><span class="ln">19</span><span class="cl">    <span class="nf">timens_commit</span><span class="p">(</span><span class="n">tsk</span><span class="p">,</span> <span class="n">ns</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">20</span><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><h1 id="10-copy_io">10. copy_io</h1>
<p>在使能CONFIG_BLOCK的情况下才有效。如果clone_flags包含CLONE_VM，则共享父进程的io上下文，否则创建新的io_context，其中主要是一些io调度的上下文。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln">1</span><span class="cl">    <span class="n">retval</span> <span class="o">=</span> <span class="nf">copy_io</span><span class="p">(</span><span class="n">clone_flags</span><span class="p">,</span> <span class="n">p</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">2</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="n">retval</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">3</span><span class="cl">        <span class="k">goto</span> <span class="n">bad_fork_cleanup_namespaces</span><span class="p">;</span>
</span></span></code></pre></div><h2 id="101-copy_io源码">10.1. copy_io源码</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln">1</span><span class="cl"><span class="c1">/// include/linux/iocontext.h
</span></span></span><span class="line"><span class="ln">2</span><span class="cl"><span class="c1"></span><span class="k">static</span> <span class="kr">inline</span> <span class="kt">int</span> <span class="nf">copy_io</span><span class="p">(</span><span class="kt">unsigned</span> <span class="kt">long</span> <span class="n">clone_flags</span><span class="p">,</span> <span class="k">struct</span> <span class="n">task_struct</span> <span class="o">*</span><span class="n">tsk</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">3</span><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="ln">4</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">current</span><span class="o">-&gt;</span><span class="n">io_context</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">5</span><span class="cl">        <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">6</span><span class="cl">    <span class="k">return</span> <span class="nf">__copy_io</span><span class="p">(</span><span class="n">clone_flags</span><span class="p">,</span> <span class="n">tsk</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">7</span><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><h2 id="102-__copy_io源码">10.2. __copy_io源码</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln"> 1</span><span class="cl"><span class="c1">/// block/blk-io.c
</span></span></span><span class="line"><span class="ln"> 2</span><span class="cl"><span class="c1"></span><span class="kt">int</span> <span class="nf">__copy_io</span><span class="p">(</span><span class="kt">unsigned</span> <span class="kt">long</span> <span class="n">clone_flags</span><span class="p">,</span> <span class="k">struct</span> <span class="n">task_struct</span> <span class="o">*</span><span class="n">tsk</span><span class="p">)</span>
</span></span><span class="line"><span class="ln"> 3</span><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="ln"> 4</span><span class="cl">    <span class="k">struct</span> <span class="n">io_context</span> <span class="o">*</span><span class="n">ioc</span> <span class="o">=</span> <span class="n">current</span><span class="o">-&gt;</span><span class="n">io_context</span><span class="p">;</span>
</span></span><span class="line"><span class="ln"> 5</span><span class="cl">
</span></span><span class="line"><span class="ln"> 6</span><span class="cl">    <span class="cm">/*
</span></span></span><span class="line"><span class="ln"> 7</span><span class="cl"><span class="cm">     * Share io context with parent, if CLONE_IO is set
</span></span></span><span class="line"><span class="ln"> 8</span><span class="cl"><span class="cm">     */</span>
</span></span><span class="line"><span class="ln"> 9</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="n">clone_flags</span> <span class="o">&amp;</span> <span class="n">CLONE_IO</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln">10</span><span class="cl">        <span class="nf">atomic_inc</span><span class="p">(</span><span class="o">&amp;</span><span class="n">ioc</span><span class="o">-&gt;</span><span class="n">active_ref</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">11</span><span class="cl">        <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">io_context</span> <span class="o">=</span> <span class="n">ioc</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">12</span><span class="cl">    <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nf">ioprio_valid</span><span class="p">(</span><span class="n">ioc</span><span class="o">-&gt;</span><span class="n">ioprio</span><span class="p">))</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln">13</span><span class="cl">        <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">io_context</span> <span class="o">=</span> <span class="nf">alloc_io_context</span><span class="p">(</span><span class="n">GFP_KERNEL</span><span class="p">,</span> <span class="n">NUMA_NO_NODE</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">14</span><span class="cl">        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">tsk</span><span class="o">-&gt;</span><span class="n">io_context</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">15</span><span class="cl">            <span class="k">return</span> <span class="o">-</span><span class="n">ENOMEM</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">16</span><span class="cl">        <span class="n">tsk</span><span class="o">-&gt;</span><span class="n">io_context</span><span class="o">-&gt;</span><span class="n">ioprio</span> <span class="o">=</span> <span class="n">ioc</span><span class="o">-&gt;</span><span class="n">ioprio</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">17</span><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="ln">18</span><span class="cl">
</span></span><span class="line"><span class="ln">19</span><span class="cl">    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">20</span><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><h1 id="11-copy_thread">11. copy_thread</h1>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln">1</span><span class="cl">    <span class="n">retval</span> <span class="o">=</span> <span class="nf">copy_thread</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">args</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">2</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="n">retval</span><span class="p">)</span>
</span></span><span class="line"><span class="ln">3</span><span class="cl">        <span class="k">goto</span> <span class="n">bad_fork_cleanup_io</span><span class="p">;</span>
</span></span></code></pre></div><h2 id="111-arm64-copy_thread源码">11.1. ARM64 copy_thread源码</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln"> 1</span><span class="cl"><span class="c1">/// arch/arm64/kernel/process.c
</span></span></span><span class="line"><span class="ln"> 2</span><span class="cl"><span class="c1"></span><span class="kt">int</span> <span class="nf">copy_thread</span><span class="p">(</span><span class="k">struct</span> <span class="n">task_struct</span> <span class="o">*</span><span class="n">p</span><span class="p">,</span> <span class="k">const</span> <span class="k">struct</span> <span class="n">kernel_clone_args</span> <span class="o">*</span><span class="n">args</span><span class="p">)</span>
</span></span><span class="line"><span class="ln"> 3</span><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="ln"> 4</span><span class="cl">    <span class="kt">unsigned</span> <span class="kt">long</span> <span class="n">clone_flags</span> <span class="o">=</span> <span class="n">args</span><span class="o">-&gt;</span><span class="n">flags</span><span class="p">;</span>
</span></span><span class="line"><span class="ln"> 5</span><span class="cl">    <span class="kt">unsigned</span> <span class="kt">long</span> <span class="n">stack_start</span> <span class="o">=</span> <span class="n">args</span><span class="o">-&gt;</span><span class="n">stack</span><span class="p">;</span>
</span></span><span class="line"><span class="ln"> 6</span><span class="cl">    <span class="kt">unsigned</span> <span class="kt">long</span> <span class="n">tls</span> <span class="o">=</span> <span class="n">args</span><span class="o">-&gt;</span><span class="n">tls</span><span class="p">;</span>
</span></span><span class="line"><span class="ln"> 7</span><span class="cl">    <span class="k">struct</span> <span class="n">pt_regs</span> <span class="o">*</span><span class="n">childregs</span> <span class="o">=</span> <span class="nf">task_pt_regs</span><span class="p">(</span><span class="n">p</span><span class="p">);</span>
</span></span><span class="line"><span class="ln"> 8</span><span class="cl">
</span></span><span class="line"><span class="ln"> 9</span><span class="cl">    <span class="nf">memset</span><span class="p">(</span><span class="o">&amp;</span><span class="n">p</span><span class="o">-&gt;</span><span class="kr">thread</span><span class="p">.</span><span class="n">cpu_context</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="k">struct</span> <span class="n">cpu_context</span><span class="p">));</span>
</span></span><span class="line"><span class="ln">10</span><span class="cl">
</span></span><span class="line"><span class="ln">11</span><span class="cl">    <span class="cm">/*
</span></span></span><span class="line"><span class="ln">12</span><span class="cl"><span class="cm">     * In case p was allocated the same task_struct pointer as some
</span></span></span><span class="line"><span class="ln">13</span><span class="cl"><span class="cm">     * other recently-exited task, make sure p is disassociated from
</span></span></span><span class="line"><span class="ln">14</span><span class="cl"><span class="cm">     * any cpu that may have run that now-exited task recently.
</span></span></span><span class="line"><span class="ln">15</span><span class="cl"><span class="cm">     * Otherwise we could erroneously skip reloading the FPSIMD
</span></span></span><span class="line"><span class="ln">16</span><span class="cl"><span class="cm">     * registers for p.
</span></span></span><span class="line"><span class="ln">17</span><span class="cl"><span class="cm">     */</span>
</span></span><span class="line"><span class="ln">18</span><span class="cl">    <span class="nf">fpsimd_flush_task_state</span><span class="p">(</span><span class="n">p</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">19</span><span class="cl">
</span></span><span class="line"><span class="ln">20</span><span class="cl">    <span class="nf">ptrauth_thread_init_kernel</span><span class="p">(</span><span class="n">p</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">21</span><span class="cl">
</span></span><span class="line"><span class="ln">22</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="nf">likely</span><span class="p">(</span><span class="o">!</span><span class="n">args</span><span class="o">-&gt;</span><span class="n">fn</span><span class="p">))</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln">23</span><span class="cl">        <span class="o">*</span><span class="n">childregs</span> <span class="o">=</span> <span class="o">*</span><span class="nf">current_pt_regs</span><span class="p">();</span>
</span></span><span class="line"><span class="ln">24</span><span class="cl">        <span class="n">childregs</span><span class="o">-&gt;</span><span class="n">regs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">25</span><span class="cl">
</span></span><span class="line"><span class="ln">26</span><span class="cl">        <span class="cm">/*
</span></span></span><span class="line"><span class="ln">27</span><span class="cl"><span class="cm">         * Read the current TLS pointer from tpidr_el0 as it may be
</span></span></span><span class="line"><span class="ln">28</span><span class="cl"><span class="cm">         * out-of-sync with the saved value.
</span></span></span><span class="line"><span class="ln">29</span><span class="cl"><span class="cm">         */</span>
</span></span><span class="line"><span class="ln">30</span><span class="cl">        <span class="o">*</span><span class="nf">task_user_tls</span><span class="p">(</span><span class="n">p</span><span class="p">)</span> <span class="o">=</span> <span class="nf">read_sysreg</span><span class="p">(</span><span class="n">tpidr_el0</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">31</span><span class="cl">        <span class="k">if</span> <span class="p">(</span><span class="nf">system_supports_tpidr2</span><span class="p">())</span>
</span></span><span class="line"><span class="ln">32</span><span class="cl">            <span class="n">p</span><span class="o">-&gt;</span><span class="kr">thread</span><span class="p">.</span><span class="n">tpidr2_el0</span> <span class="o">=</span> <span class="nf">read_sysreg_s</span><span class="p">(</span><span class="n">SYS_TPIDR2_EL0</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">33</span><span class="cl">
</span></span><span class="line"><span class="ln">34</span><span class="cl">        <span class="k">if</span> <span class="p">(</span><span class="n">stack_start</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln">35</span><span class="cl">            <span class="k">if</span> <span class="p">(</span><span class="nf">is_compat_thread</span><span class="p">(</span><span class="nf">task_thread_info</span><span class="p">(</span><span class="n">p</span><span class="p">)))</span>
</span></span><span class="line"><span class="ln">36</span><span class="cl">                <span class="n">childregs</span><span class="o">-&gt;</span><span class="n">compat_sp</span> <span class="o">=</span> <span class="n">stack_start</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">37</span><span class="cl">            <span class="k">else</span>
</span></span><span class="line"><span class="ln">38</span><span class="cl">                <span class="n">childregs</span><span class="o">-&gt;</span><span class="n">sp</span> <span class="o">=</span> <span class="n">stack_start</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">39</span><span class="cl">        <span class="p">}</span>
</span></span><span class="line"><span class="ln">40</span><span class="cl">
</span></span><span class="line"><span class="ln">41</span><span class="cl">        <span class="cm">/*
</span></span></span><span class="line"><span class="ln">42</span><span class="cl"><span class="cm">         * If a TLS pointer was passed to clone, use it for the new
</span></span></span><span class="line"><span class="ln">43</span><span class="cl"><span class="cm">         * thread.  We also reset TPIDR2 if it&#39;s in use.
</span></span></span><span class="line"><span class="ln">44</span><span class="cl"><span class="cm">         */</span>
</span></span><span class="line"><span class="ln">45</span><span class="cl">        <span class="k">if</span> <span class="p">(</span><span class="n">clone_flags</span> <span class="o">&amp;</span> <span class="n">CLONE_SETTLS</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln">46</span><span class="cl">            <span class="n">p</span><span class="o">-&gt;</span><span class="kr">thread</span><span class="p">.</span><span class="n">uw</span><span class="p">.</span><span class="n">tp_value</span> <span class="o">=</span> <span class="n">tls</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">47</span><span class="cl">            <span class="n">p</span><span class="o">-&gt;</span><span class="kr">thread</span><span class="p">.</span><span class="n">tpidr2_el0</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">48</span><span class="cl">        <span class="p">}</span>
</span></span><span class="line"><span class="ln">49</span><span class="cl">    <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln">50</span><span class="cl">        <span class="cm">/*
</span></span></span><span class="line"><span class="ln">51</span><span class="cl"><span class="cm">         * A kthread has no context to ERET to, so ensure any buggy
</span></span></span><span class="line"><span class="ln">52</span><span class="cl"><span class="cm">         * ERET is treated as an illegal exception return.
</span></span></span><span class="line"><span class="ln">53</span><span class="cl"><span class="cm">         *
</span></span></span><span class="line"><span class="ln">54</span><span class="cl"><span class="cm">         * When a user task is created from a kthread, childregs will
</span></span></span><span class="line"><span class="ln">55</span><span class="cl"><span class="cm">         * be initialized by start_thread() or start_compat_thread().
</span></span></span><span class="line"><span class="ln">56</span><span class="cl"><span class="cm">         */</span>
</span></span><span class="line"><span class="ln">57</span><span class="cl">        <span class="nf">memset</span><span class="p">(</span><span class="n">childregs</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="k">struct</span> <span class="n">pt_regs</span><span class="p">));</span>
</span></span><span class="line"><span class="ln">58</span><span class="cl">        <span class="n">childregs</span><span class="o">-&gt;</span><span class="n">pstate</span> <span class="o">=</span> <span class="n">PSR_MODE_EL1h</span> <span class="o">|</span> <span class="n">PSR_IL_BIT</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">59</span><span class="cl">
</span></span><span class="line"><span class="ln">60</span><span class="cl">        <span class="n">p</span><span class="o">-&gt;</span><span class="kr">thread</span><span class="p">.</span><span class="n">cpu_context</span><span class="p">.</span><span class="n">x19</span> <span class="o">=</span> <span class="p">(</span><span class="kt">unsigned</span> <span class="kt">long</span><span class="p">)</span><span class="n">args</span><span class="o">-&gt;</span><span class="n">fn</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">61</span><span class="cl">        <span class="n">p</span><span class="o">-&gt;</span><span class="kr">thread</span><span class="p">.</span><span class="n">cpu_context</span><span class="p">.</span><span class="n">x20</span> <span class="o">=</span> <span class="p">(</span><span class="kt">unsigned</span> <span class="kt">long</span><span class="p">)</span><span class="n">args</span><span class="o">-&gt;</span><span class="n">fn_arg</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">62</span><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="ln">63</span><span class="cl">    <span class="n">p</span><span class="o">-&gt;</span><span class="kr">thread</span><span class="p">.</span><span class="n">cpu_context</span><span class="p">.</span><span class="n">pc</span> <span class="o">=</span> <span class="p">(</span><span class="kt">unsigned</span> <span class="kt">long</span><span class="p">)</span><span class="n">ret_from_fork</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">64</span><span class="cl">    <span class="n">p</span><span class="o">-&gt;</span><span class="kr">thread</span><span class="p">.</span><span class="n">cpu_context</span><span class="p">.</span><span class="n">sp</span> <span class="o">=</span> <span class="p">(</span><span class="kt">unsigned</span> <span class="kt">long</span><span class="p">)</span><span class="n">childregs</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">65</span><span class="cl">    <span class="cm">/*
</span></span></span><span class="line"><span class="ln">66</span><span class="cl"><span class="cm">     * For the benefit of the unwinder, set up childregs-&gt;stackframe
</span></span></span><span class="line"><span class="ln">67</span><span class="cl"><span class="cm">     * as the final frame for the new task.
</span></span></span><span class="line"><span class="ln">68</span><span class="cl"><span class="cm">     */</span>
</span></span><span class="line"><span class="ln">69</span><span class="cl">    <span class="n">p</span><span class="o">-&gt;</span><span class="kr">thread</span><span class="p">.</span><span class="n">cpu_context</span><span class="p">.</span><span class="n">fp</span> <span class="o">=</span> <span class="p">(</span><span class="kt">unsigned</span> <span class="kt">long</span><span class="p">)</span><span class="n">childregs</span><span class="o">-&gt;</span><span class="n">stackframe</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">70</span><span class="cl">
</span></span><span class="line"><span class="ln">71</span><span class="cl">    <span class="nf">ptrace_hw_copy_thread</span><span class="p">(</span><span class="n">p</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">72</span><span class="cl">
</span></span><span class="line"><span class="ln">73</span><span class="cl">    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">74</span><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><p>对于用户态，childregs复制current_pt_regs，childregs-&gt;sp指向用户栈，x0设为0作为fork返回值，这样用户态可以识别到这是子进程。
对于内核态调用的fork，childregs清零，x19和x20分别记录args-&gt;fn和args-&gt;fn_arg。</p>
<p>其他值是相同的</p>
<ol>
<li><code>p-&gt;thread.cpu_context.sp</code>指向childregs，指向内核栈<code>task-&gt;stack</code>的栈底+sizeof(struct pt_regs)的位置。</li>
<li>cpu_context.pc为ret_from_fork。</li>
</ol>
<p>调度时，首先使用内核栈，找到cpu_context.sp和pc，跳转到ret_from_fork；
如果是内核线程，将x20赋值到x0，跳转x19指向的函数，继续使用内核栈。
如果是用户程序，返回用户态时，从childregs取出用户栈地址，恢复用户上下文。</p>

    </div><div class="post_comments">
  
  
  
</div>



  </article>
<aside class="sidebar">
  <section class="sidebar_inner">
    <br>
    
  
  <div class="search">
    <input type="search" class="search_field form_field" placeholder='搜索内容...' id="find" autocomplete="off" data-scope='post'>
    <label for="find" class="search_label"><svg class="icon">
  <title>search</title>
  <use xlink:href="#search"></use>
</svg>

    </label>
    
    <div class="search_results results"></div>
  </div>

        <div class="author_header">
          <img src="https://kingdix10.gitee.io/logos/icon_yellow_transparent.png" alt="kingdix10 photo">
          <h2>kingdix10</h2>
        </div>
      <div class="author_bio">
        拾月国度
      </div>
      <a href='https://kingdix10.gitee.io/about/' class="button mt-1" role="button" title='阅读更多'>阅读更多</a>

    
      
    
    <h2 class="mt-4">最新文章</h2>
    <ul class="flex-column">
      <li>
        <a href="https://kingdix10.gitee.io/post/kernel/linux-6.6/kdump_crash/arm64_setup/" class="nav-link" title="ARM64 Crash调试环境搭建">ARM64 Crash调试环境搭建</a>
      </li>
      <li>
        <a href="https://kingdix10.gitee.io/post/kernel/linux-6.6/kdump_crash/help/" class="nav-link" title="Crash帮助信息">Crash帮助信息</a>
      </li>
      <li>
        <a href="https://kingdix10.gitee.io/post/kernel/linux-6.1/thermal/thermal/" class="nav-link" title="linux thermal子系统简介">linux thermal子系统简介</a>
      </li>
      <li>
        <a href="https://kingdix10.gitee.io/post/kernel/linux-6.1/time/clocksource_clockevent/" class="nav-link" title="linux内核时间子系统（三）">linux内核时间子系统（三）</a>
      </li>
      <li>
        <a href="https://kingdix10.gitee.io/post/kernel/linux-6.1/time/timekeeping/" class="nav-link" title="linux内核时间子系统（二）">linux内核时间子系统（二）</a>
      </li>
      <li>
        <a href="https://kingdix10.gitee.io/post/kernel/linux-6.1/time/tim/" class="nav-link" title="linux内核时间子系统（一）">linux内核时间子系统（一）</a>
      </li>
      <li>
        <a href="https://kingdix10.gitee.io/post/kernel/linux-6.1/device_driver/device_model/" class="nav-link" title="Linux内核驱动模型（四）核心结构体">Linux内核驱动模型（四）核心结构体</a>
      </li>
      <li>
        <a href="https://kingdix10.gitee.io/post/kernel/linux-6.1/device_driver/initcall/" class="nav-link" title="Linux内核驱动模型（三）驱动初始化">Linux内核驱动模型（三）驱动初始化</a>
      </li>
      <li>
        <a href="https://kingdix10.gitee.io/post/kernel/linux-6.1/fdt/dt_to_dt/" class="nav-link" title="Linux内核驱动模型（二）设备树转换">Linux内核驱动模型（二）设备树转换</a>
      </li>
      <li>
        <a href="https://kingdix10.gitee.io/post/kernel/linux-6.1/fdt/fdt_dt/" class="nav-link" title="Linux内核驱动模型（一）设备树展开">Linux内核驱动模型（一）设备树展开</a>
      </li>
    </ul>
    <div>
      <h2 class="mt-4 taxonomy" id="categories-section">分类</h2>
      <nav class="tags_nav">
        <a href='https://kingdix10.gitee.io/categories/%E8%BF%9B%E7%A8%8B%E7%AE%A1%E7%90%86/' class="post_tag button button_translucent" title="进程管理">
          进程管理
          <span class="button_tally">11</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/categories/%E8%AE%BE%E5%A4%87%E6%A8%A1%E5%9E%8B/' class="post_tag button button_translucent" title="设备模型">
          设备模型
          <span class="button_tally">5</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/categories/4412/' class="post_tag button button_translucent" title="4412">
          4412
          <span class="button_tally">3</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/categories/c%E8%AF%AD%E8%A8%80/' class="post_tag button button_translucent" title="c语言">
          C语言
          <span class="button_tally">3</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/categories/%E5%90%AF%E5%8A%A8%E6%B5%81%E7%A8%8B/' class="post_tag button button_translucent" title="启动流程">
          启动流程
          <span class="button_tally">3</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/categories/%E6%97%B6%E9%97%B4%E5%AD%90%E7%B3%BB%E7%BB%9F/' class="post_tag button button_translucent" title="时间子系统">
          时间子系统
          <span class="button_tally">3</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/categories/kdump-crash/' class="post_tag button button_translucent" title="kdump-crash">
          KDUMP-CRASH
          <span class="button_tally">2</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/categories/%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/' class="post_tag button button_translucent" title="环境搭建">
          环境搭建
          <span class="button_tally">2</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/categories/linux%E5%91%BD%E4%BB%A4/' class="post_tag button button_translucent" title="linux命令">
          LINUX命令
          <span class="button_tally">1</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/categories/thermal%E5%AD%90%E7%B3%BB%E7%BB%9F/' class="post_tag button button_translucent" title="thermal子系统">
          THERMAL子系统
          <span class="button_tally">1</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/categories/%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86/' class="post_tag button button_translucent" title="内存管理">
          内存管理
          <span class="button_tally">1</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/categories/%E5%86%85%E6%A0%B8%E5%9F%BA%E7%A1%80/' class="post_tag button button_translucent" title="内核基础">
          内核基础
          <span class="button_tally">1</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/categories/%E5%86%85%E6%A0%B8%E8%B0%83%E8%AF%95/' class="post_tag button button_translucent" title="内核调试">
          内核调试
          <span class="button_tally">1</span>
        </a>
        
        
      </nav>
    </div>
    <div>
      <h2 class="mt-4 taxonomy" id="series-section">专栏</h2>
      <nav class="tags_nav">
        <a href='https://kingdix10.gitee.io/series/%E8%BF%9B%E7%A8%8B%E7%AE%A1%E7%90%86/' class="post_tag button button_translucent" title="进程管理">
          进程管理
          <span class="button_tally">11</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/series/%E8%AE%BE%E5%A4%87%E9%A9%B1%E5%8A%A8%E6%A8%A1%E5%9E%8B/' class="post_tag button button_translucent" title="设备驱动模型">
          设备驱动模型
          <span class="button_tally">5</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/series/%E6%97%B6%E9%97%B4%E5%AD%90%E7%B3%BB%E7%BB%9F/' class="post_tag button button_translucent" title="时间子系统">
          时间子系统
          <span class="button_tally">3</span>
        </a>
        
        
      </nav>
    </div>
    <div>
      <h2 class="mt-4 taxonomy" id="tags-section">标签</h2>
      <nav class="tags_nav">
        <a href='https://kingdix10.gitee.io/tags/linux%E5%86%85%E6%A0%B8/' class="post_tag button button_translucent" title="linux内核">
          LINUX内核
          <span class="button_tally">19</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/tags/linux-6.1/' class="post_tag button button_translucent" title="linux-6.1">
          LINUX-6.1
          <span class="button_tally">12</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/tags/linux-6.6/' class="post_tag button button_translucent" title="linux-6.6">
          LINUX-6.6
          <span class="button_tally">9</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/tags/%E5%86%85%E6%A0%B8%E9%A9%B1%E5%8A%A8/' class="post_tag button button_translucent" title="内核驱动">
          内核驱动
          <span class="button_tally">9</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/tags/%E8%BF%9B%E7%A8%8B%E7%AE%A1%E7%90%86/' class="post_tag button button_translucent" title="进程管理">
          进程管理
          <span class="button_tally">6</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/tags/linux/' class="post_tag button button_translucent" title="linux">
          LINUX
          <span class="button_tally">5</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/tags/4412/' class="post_tag button button_translucent" title="4412">
          4412
          <span class="button_tally">3</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/tags/c%E8%AF%AD%E8%A8%80/' class="post_tag button button_translucent" title="c语言">
          C语言
          <span class="button_tally">3</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/tags/%E5%90%AF%E5%8A%A8%E6%B5%81%E7%A8%8B/' class="post_tag button button_translucent" title="启动流程">
          启动流程
          <span class="button_tally">3</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/tags/%E5%B7%A5%E5%85%B7/' class="post_tag button button_translucent" title="工具">
          工具
          <span class="button_tally">3</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/tags/kdump-crash/' class="post_tag button button_translucent" title="kdump-crash">
          KDUMP-CRASH
          <span class="button_tally">2</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/tags/%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/' class="post_tag button button_translucent" title="环境搭建">
          环境搭建
          <span class="button_tally">2</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/tags/arm64/' class="post_tag button button_translucent" title="arm64">
          ARM64
          <span class="button_tally">1</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/tags/u-boot/' class="post_tag button button_translucent" title="u-boot">
          U-BOOT
          <span class="button_tally">1</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/tags/%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86/' class="post_tag button button_translucent" title="内存管理">
          内存管理
          <span class="button_tally">1</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/tags/%E5%86%85%E6%A0%B8%E8%B0%83%E8%AF%95/' class="post_tag button button_translucent" title="内核调试">
          内核调试
          <span class="button_tally">1</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/' class="post_tag button button_translucent" title="数据结构">
          数据结构
          <span class="button_tally">1</span>
        </a>
        
        <a href='https://kingdix10.gitee.io/tags/%E8%B0%83%E8%AF%95/' class="post_tag button button_translucent" title="调试">
          调试
          <span class="button_tally">1</span>
        </a>
        
        
      </nav>
    </div>
  </section>
</aside>

  
</div>
    </main><svg width="0" height="0" class="hidden">
  <symbol viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg" id="facebook">
    <path d="M437 0H75C33.648 0 0 33.648 0 75v362c0 41.352 33.648 75 75 75h151V331h-60v-90h60v-61c0-49.629 40.371-90 90-90h91v90h-91v61h91l-15 90h-76v181h121c41.352 0 75-33.648 75-75V75c0-41.352-33.648-75-75-75zm0 0"></path>
  </symbol>
  <symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 18.001 18.001" id="twitter">
    <path d="M15.891 4.013c.808-.496 1.343-1.173 1.605-2.034a8.68 8.68 0 0 1-2.351.861c-.703-.756-1.593-1.14-2.66-1.14-1.043 0-1.924.366-2.643 1.078a3.56 3.56 0 0 0-1.076 2.605c0 .309.039.585.117.819-3.076-.105-5.622-1.381-7.628-3.837-.34.601-.51 1.213-.51 1.846 0 1.301.549 2.332 1.645 3.089-.625-.053-1.176-.211-1.645-.47 0 .929.273 1.705.82 2.388a3.623 3.623 0 0 0 2.115 1.291c-.312.08-.641.118-.979.118-.312 0-.533-.026-.664-.083.23.757.664 1.371 1.291 1.841a3.652 3.652 0 0 0 2.152.743C4.148 14.173 2.625 14.69.902 14.69c-.422 0-.721-.006-.902-.038 1.697 1.102 3.586 1.649 5.676 1.649 2.139 0 4.029-.542 5.674-1.626 1.645-1.078 2.859-2.408 3.639-3.974a10.77 10.77 0 0 0 1.172-4.892v-.468a7.788 7.788 0 0 0 1.84-1.921 8.142 8.142 0 0 1-2.11.593z"
      ></path>
  </symbol>
  <symbol aria-hidden="true" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" id="mail">
    <path  d="M502.3 190.8c3.9-3.1 9.7-.2 9.7 4.7V400c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V195.6c0-5 5.7-7.8 9.7-4.7 22.4 17.4 52.1 39.5 154.1 113.6 21.1 15.4 56.7 47.8 92.2 47.6 35.7.3 72-32.8 92.3-47.6 102-74.1 131.6-96.3 154-113.7zM256 320c23.2.4 56.6-29.2 73.4-41.4 132.7-96.3 142.8-104.7 173.4-128.7 5.8-4.5 9.2-11.5 9.2-18.9v-19c0-26.5-21.5-48-48-48H48C21.5 64 0 85.5 0 112v19c0 7.4 3.4 14.3 9.2 18.9 30.6 23.9 40.7 32.4 173.4 128.7 16.8 12.2 50.2 41.8 73.4 41.4z"></path>
  </symbol>
  <symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" id="calendar">
    <path d="M452 40h-24V0h-40v40H124V0H84v40H60C26.916 40 0 66.916 0 100v352c0 33.084 26.916 60 60 60h392c33.084 0 60-26.916 60-60V100c0-33.084-26.916-60-60-60zm20 412c0 11.028-8.972 20-20 20H60c-11.028 0-20-8.972-20-20V188h432v264zm0-304H40v-48c0-11.028 8.972-20 20-20h24v40h40V80h264v40h40V80h24c11.028 0 20 8.972 20 20v48z"></path>
    <path d="M76 230h40v40H76zm80 0h40v40h-40zm80 0h40v40h-40zm80 0h40v40h-40zm80 0h40v40h-40zM76 310h40v40H76zm80 0h40v40h-40zm80 0h40v40h-40zm80 0h40v40h-40zM76 390h40v40H76zm80 0h40v40h-40zm80 0h40v40h-40zm80 0h40v40h-40zm80-80h40v40h-40z"></path>
  </symbol>
  <symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" id="github">
    <path d="M255.968 5.329C114.624 5.329 0 120.401 0 262.353c0 113.536 73.344 209.856 175.104 243.872 12.8 2.368 17.472-5.568 17.472-12.384 0-6.112-.224-22.272-.352-43.712-71.2 15.52-86.24-34.464-86.24-34.464-11.616-29.696-28.416-37.6-28.416-37.6-23.264-15.936 1.728-15.616 1.728-15.616 25.696 1.824 39.2 26.496 39.2 26.496 22.848 39.264 59.936 27.936 74.528 21.344 2.304-16.608 8.928-27.936 16.256-34.368-56.832-6.496-116.608-28.544-116.608-127.008 0-28.064 9.984-51.008 26.368-68.992-2.656-6.496-11.424-32.64 2.496-68 0 0 21.504-6.912 70.4 26.336 20.416-5.696 42.304-8.544 64.096-8.64 21.728.128 43.648 2.944 64.096 8.672 48.864-33.248 70.336-26.336 70.336-26.336 13.952 35.392 5.184 61.504 2.56 68 16.416 17.984 26.304 40.928 26.304 68.992 0 98.72-59.84 120.448-116.864 126.816 9.184 7.936 17.376 23.616 17.376 47.584 0 34.368-.32 62.08-.32 70.496 0 6.88 4.608 14.88 17.6 12.352C438.72 472.145 512 375.857 512 262.353 512 120.401 397.376 5.329 255.968 5.329z"></path>
  </symbol>

  <symbol width="128px" height="128px" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg" id="gitee">
      <g id="LOGO" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
          <g id="Artboard-7" transform="translate(-192.000000, -115.000000)" fill="#C71D23">
              <path d="M228,115 C247.882251,115 264,131.117749 264,151 C264,170.882251 247.882251,187 228,187 C208.117749,187 192,170.882251 192,151 C192,131.117749 208.117749,115 228,115 Z M246.223335,131 C246.222967,131 246.2226,131 246.222232,131.001102 L221.33326,131.001102 C213.969504,131.001102 208,136.970606 208,144.334362 L208,169.222232 C208,170.204066 208.795934,171 209.777768,171 L236.000329,171 C242.627564,171 248,165.627564 248,159.000329 L248,148.778425 C248,147.796591 247.204066,147.000657 246.222232,147.000657 L225.7779,147.000657 C224.796248,147.001123 224.000389,147.796773 223.999667,148.778425 L223.998503,153.222667 C223.997802,154.155409 224.715909,154.920565 225.629522,154.994969 L225.775805,155.00042 L225.775805,155.00042 L238.222276,155.000317 C239.155019,155.000295 239.919992,155.718618 239.994164,156.63225 L240.000044,156.77807 L240.000044,156.77807 L240.000044,157.666909 C240.000044,160.612411 237.612243,163.000213 234.66674,163.000213 L217.776621,163.000213 C216.794928,163.000164 215.999101,162.204358 215.999025,161.222665 L215.998559,144.334184 C215.998337,141.462319 218.268172,139.120556 221.111731,139.005187 L221.331716,139.00088 L221.331716,139.00088 L246.21727,139.00088 C247.198674,138.999777 247.994429,138.204515 247.996141,137.223112 L247.998897,132.77887 C248.000609,131.797037 247.205169,131.000609 246.223335,131 Z" id="logo_gitee_g_red"></path>
          </g>
      </g>
  </symbol>

  <symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 212 212" id="gitlab">
    <path d="M12.3 74.7h54L43.3 3c-1-3.6-6.4-3.6-7.6 0L12.3 74.8z" />
    <path d="M12.3 74.7L.5 111c-1 3.2 0 6.8 3 8.8l101.6 74-92.5-119z"/>
    <path d="M105 193.7l-38.6-119h-54l92.7 119z"/>
    <path d="M105 193.7l38.7-119H66.4l38.7 119z"/>
    <path d="M105 193.7l38.7-119H198l-93 119z"/>
    <path d="M198 74.7l11.6 36.2c1 3 0 6.6-3 8.6l-101.5 74 93-119z"/>
    <path d="M198 74.7h-54.3L167 3c1.2-3.6 6.4-3.6 7.6 0L198 74.8z"/>
  </symbol>
  <symbol viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" id="rss">
    <circle cx="3.429" cy="20.571" r="3.429"></circle>
    <path d="M11.429 24h4.57C15.999 15.179 8.821 8.001 0 8v4.572c6.302.001 11.429 5.126 11.429 11.428z"></path>
    <path d="M24 24C24 10.766 13.234 0 0 0v4.571c10.714 0 19.43 8.714 19.43 19.429z"></path>
  </symbol>
  <symbol viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg" id="linkedin">
    <path d="M437 0H75C33.648 0 0 33.648 0 75v362c0 41.352 33.648 75 75 75h362c41.352 0 75-33.648 75-75V75c0-41.352-33.648-75-75-75zM181 406h-60V196h60zm0-240h-60v-60h60zm210 240h-60V286c0-16.54-13.46-30-30-30s-30 13.46-30 30v120h-60V196h60v11.309C286.719 202.422 296.93 196 316 196c40.691.043 75 36.547 75 79.688zm0 0"></path>
  </symbol>
  <symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 612 612" id="to-top">
    <path d="M604.501 440.509L325.398 134.956c-5.331-5.357-12.423-7.627-19.386-7.27-6.989-.357-14.056 1.913-19.387 7.27L7.499 440.509c-9.999 10.024-9.999 26.298 0 36.323s26.223 10.024 36.222 0l262.293-287.164L568.28 476.832c9.999 10.024 26.222 10.024 36.221 0 9.999-10.023 9.999-26.298 0-36.323z"></path>
  </symbol>
  <symbol viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg" id="carly">
    <path d="M504.971 239.029L448 182.059V84c0-46.317-37.682-84-84-84h-44c-13.255 0-24 10.745-24 24s10.745 24 24 24h44c19.851 0 36 16.149 36 36v108c0 6.365 2.529 12.47 7.029 16.971L454.059 256l-47.029 47.029A24.002 24.002 0 0 0 400 320v108c0 19.851-16.149 36-36 36h-44c-13.255 0-24 10.745-24 24s10.745 24 24 24h44c46.318 0 84-37.683 84-84v-98.059l56.971-56.971c9.372-9.372 9.372-24.568 0-33.941zM112 192V84c0-19.851 16.149-36 36-36h44c13.255 0 24-10.745 24-24S205.255 0 192 0h-44c-46.318 0-84 37.683-84 84v98.059l-56.971 56.97c-9.373 9.373-9.373 24.568 0 33.941L64 329.941V428c0 46.317 37.682 84 84 84h44c13.255 0 24-10.745 24-24s-10.745-24-24-24h-44c-19.851 0-36-16.149-36-36V320c0-6.365-2.529-12.47-7.029-16.971L57.941 256l47.029-47.029A24.002 24.002 0 0 0 112 192z"></path>
  </symbol>
  <symbol viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" id="copy">
    <path d="M23 2.75A2.75 2.75 0 0 0 20.25 0H8.75A2.75 2.75 0 0 0 6 2.75v13.5A2.75 2.75 0 0 0 8.75 19h11.5A2.75 2.75 0 0 0 23 16.25zM18.25 14.5h-7.5a.75.75 0 0 1 0-1.5h7.5a.75.75 0 0 1 0 1.5zm0-3h-7.5a.75.75 0 0 1 0-1.5h7.5a.75.75 0 0 1 0 1.5zm0-3h-7.5a.75.75 0 0 1 0-1.5h7.5a.75.75 0 0 1 0 1.5z"></path>
    <path d="M8.75 20.5a4.255 4.255 0 0 1-4.25-4.25V2.75c0-.086.02-.166.025-.25H3.75A2.752 2.752 0 0 0 1 5.25v16A2.752 2.752 0 0 0 3.75 24h12a2.752 2.752 0 0 0 2.75-2.75v-.75z"></path>
  </symbol>
  <symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512.001 512.001" id="closeme">
    <path d="M284.286 256.002L506.143 34.144c7.811-7.811 7.811-20.475 0-28.285-7.811-7.81-20.475-7.811-28.285 0L256 227.717 34.143 5.859c-7.811-7.811-20.475-7.811-28.285 0-7.81 7.811-7.811 20.475 0 28.285l221.857 221.857L5.858 477.859c-7.811 7.811-7.811 20.475 0 28.285a19.938 19.938 0 0 0 14.143 5.857 19.94 19.94 0 0 0 14.143-5.857L256 284.287l221.857 221.857c3.905 3.905 9.024 5.857 14.143 5.857s10.237-1.952 14.143-5.857c7.811-7.811 7.811-20.475 0-28.285L284.286 256.002z"></path>
  </symbol>
  <symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" id="open-menu">
    <path d="M492 236H20c-11.046 0-20 8.954-20 20s8.954 20 20 20h472c11.046 0 20-8.954 20-20s-8.954-20-20-20zm0-160H20C8.954 76 0 84.954 0 96s8.954 20 20 20h472c11.046 0 20-8.954 20-20s-8.954-20-20-20zm0 320H20c-11.046 0-20 8.954-20 20s8.954 20 20 20h472c11.046 0 20-8.954 20-20s-8.954-20-20-20z"></path>
  </symbol>
  <symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" id="instagram">
    <path d="M12 2.163c3.204 0 3.584.012 4.85.07 3.252.148 4.771 1.691 4.919 4.919.058 1.265.069 1.645.069 4.849 0 3.205-.012 3.584-.069 4.849-.149 3.225-1.664 4.771-4.919 4.919-1.266.058-1.644.07-4.85.07-3.204 0-3.584-.012-4.849-.07-3.26-.149-4.771-1.699-4.919-4.92-.058-1.265-.07-1.644-.07-4.849 0-3.204.013-3.583.07-4.849.149-3.227 1.664-4.771 4.919-4.919 1.266-.057 1.645-.069 4.849-.069zm0-2.163c-3.259 0-3.667.014-4.947.072-4.358.2-6.78 2.618-6.98 6.98-.059 1.281-.073 1.689-.073 4.948 0 3.259.014 3.668.072 4.948.2 4.358 2.618 6.78 6.98 6.98 1.281.058 1.689.072 4.948.072 3.259 0 3.668-.014 4.948-.072 4.354-.2 6.782-2.618 6.979-6.98.059-1.28.073-1.689.073-4.948 0-3.259-.014-3.667-.072-4.947-.196-4.354-2.617-6.78-6.979-6.98-1.281-.059-1.69-.073-4.949-.073zm0 5.838c-3.403 0-6.162 2.759-6.162 6.162s2.759 6.163 6.162 6.163 6.162-2.759 6.162-6.163c0-3.403-2.759-6.162-6.162-6.162zm0 10.162c-2.209 0-4-1.79-4-4 0-2.209 1.791-4 4-4s4 1.791 4 4c0 2.21-1.791 4-4 4zm6.406-11.845c-.796 0-1.441.645-1.441 1.44s.645 1.44 1.441 1.44c.795 0 1.439-.645 1.439-1.44s-.644-1.44-1.439-1.44z"/>
  </symbol>
  <symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" id=youtube>
    <path d="M19.615 3.184c-3.604-.246-11.631-.245-15.23 0-3.897.266-4.356 2.62-4.385 8.816.029 6.185.484 8.549 4.385 8.816 3.6.245 11.626.246 15.23 0 3.897-.266 4.356-2.62 4.385-8.816-.029-6.185-.484-8.549-4.385-8.816zm-10.615 12.816v-8l8 3.993-8 4.007z"/>
  </symbol>
  <symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" id="stackoverflow">
    <path d="M21 27v-8h3v11H0V19h3v8h18z"></path><path d="M17.1.2L15 1.8l7.9 10.6 2.1-1.6L17.1.2zm3.7 14.7L10.6 6.4l1.7-2 10.2 8.5-1.7 2zM7.2 12.3l12 5.6 1.1-2.4-12-5.6-1.1 2.4zm-1.8 6.8l13.56 1.96.17-2.38-13.26-2.55-.47 2.97zM19 25H5v-3h14v3z"></path>
  </symbol>
  <symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" id="xing">
    <path d="M18.188 0c-.517 0-.741.325-.927.66 0 0-7.455 13.224-7.702 13.657.015.024 4.919 9.023 4.919 9.023.17.308.436.66.967.66h3.454c.211 0 .375-.078.463-.22.089-.151.089-.346-.009-.536l-4.879-8.916c-.004-.006-.004-.016 0-.022L22.139.756c.095-.191.097-.387.006-.535C22.056.078 21.894 0 21.686 0h-3.498zM3.648 4.74c-.211 0-.385.074-.473.216-.09.149-.078.339.02.531l2.34 4.05c.004.01.004.016 0 .021L1.86 16.051c-.099.188-.093.381 0 .529.085.142.239.234.45.234h3.461c.518 0 .766-.348.945-.667l3.734-6.609-2.378-4.155c-.172-.315-.434-.659-.962-.659H3.648v.016z"/>
  </symbol>
  <symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 71 55" id="discord">
    <path d="M60.1045 4.8978C55.5792 2.8214 50.7265 1.2916 45.6527 0.41542C45.5603 0.39851 45.468 0.440769 45.4204 0.525289C44.7963 1.6353 44.105 3.0834 43.6209 4.2216C38.1637 3.4046 32.7345 3.4046 27.3892 4.2216C26.905 3.0581 26.1886 1.6353 25.5617 0.525289C25.5141 0.443589 25.4218 0.40133 25.3294 0.41542C20.2584 1.2888 15.4057 2.8186 10.8776 4.8978C10.8384 4.9147 10.8048 4.9429 10.7825 4.9795C1.57795 18.7309 -0.943561 32.1443 0.293408 45.3914C0.299005 45.4562 0.335386 45.5182 0.385761 45.5576C6.45866 50.0174 12.3413 52.7249 18.1147 54.5195C18.2071 54.5477 18.305 54.5139 18.3638 54.4378C19.7295 52.5728 20.9469 50.6063 21.9907 48.5383C22.0523 48.4172 21.9935 48.2735 21.8676 48.2256C19.9366 47.4931 18.0979 46.6 16.3292 45.5858C16.1893 45.5041 16.1781 45.304 16.3068 45.2082C16.679 44.9293 17.0513 44.6391 17.4067 44.3461C17.471 44.2926 17.5606 44.2813 17.6362 44.3151C29.2558 49.6202 41.8354 49.6202 53.3179 44.3151C53.3935 44.2785 53.4831 44.2898 53.5502 44.3433C53.9057 44.6363 54.2779 44.9293 54.6529 45.2082C54.7816 45.304 54.7732 45.5041 54.6333 45.5858C52.8646 46.6197 51.0259 47.4931 49.0921 48.2228C48.9662 48.2707 48.9102 48.4172 48.9718 48.5383C50.038 50.6034 51.2554 52.5699 52.5959 54.435C52.6519 54.5139 52.7526 54.5477 52.845 54.5195C58.6464 52.7249 64.529 50.0174 70.6019 45.5576C70.6551 45.5182 70.6887 45.459 70.6943 45.3942C72.1747 30.0791 68.2147 16.7757 60.1968 4.9823C60.1772 4.9429 60.1437 4.9147 60.1045 4.8978ZM23.7259 37.3253C20.2276 37.3253 17.3451 34.1136 17.3451 30.1693C17.3451 26.225 20.1717 23.0133 23.7259 23.0133C27.308 23.0133 30.1626 26.2532 30.1066 30.1693C30.1066 34.1136 27.28 37.3253 23.7259 37.3253ZM47.3178 37.3253C43.8196 37.3253 40.9371 34.1136 40.9371 30.1693C40.9371 26.225 43.7636 23.0133 47.3178 23.0133C50.9 23.0133 53.7545 26.2532 53.6986 30.1693C53.6986 34.1136 50.9 37.3253 47.3178 37.3253Z"/>
  </symbol>
  <symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 17 18" id="mastodon">
    <path
    fill="#ffffff"
    d="m 15.054695,9.8859583 c -0.22611,1.1632697 -2.02517,2.4363497 -4.09138,2.6830797 -1.0774504,0.12856 -2.1382704,0.24673 -3.2694704,0.19484 -1.84996,-0.0848 -3.30971,-0.44157 -3.30971,-0.44157 0,0.1801 0.0111,0.35157 0.0333,0.51194 0.24051,1.82571 1.81034,1.93508 3.29737,1.98607 1.50088,0.0514 2.8373104,-0.37004 2.8373104,-0.37004 l 0.0617,1.35686 c 0,0 -1.0498104,0.56374 -2.9199404,0.66742 -1.03124,0.0567 -2.3117,-0.0259 -3.80308,-0.42069 -3.23454998,-0.85613 -3.79081998,-4.304 -3.87592998,-7.8024197 -0.026,-1.03871 -0.01,-2.01815 -0.01,-2.83732 0,-3.57732 2.34385998,-4.62587996 2.34385998,-4.62587996 1.18184,-0.54277 3.20976,-0.77101 5.318,-0.7882499985409 h 0.0518 C 9.8267646,0.01719834 11.856025,0.24547834 13.037775,0.78824834 c 0,0 2.34377,1.04855996 2.34377,4.62587996 0,0 0.0294,2.63937 -0.32687,4.47183"/>
 <path
    fill="#000000"
    d="m 12.616925,5.6916583 v 4.3315297 h -1.71607 V 5.8189683 c 0,-0.88624 -0.37289,-1.33607 -1.1187604,-1.33607 -0.82467,0 -1.23799,0.53361 -1.23799,1.58875 v 2.30122 h -1.70594 v -2.30122 c 0,-1.05514 -0.4134,-1.58875 -1.23808,-1.58875 -0.74587,0 -1.11876,0.44983 -1.11876,1.33607 v 4.2042197 h -1.71607 V 5.6916583 c 0,-0.88527 0.22541,-1.58876 0.67817,-2.10922 0.46689,-0.52047 1.07833,-0.78727 1.83735,-0.78727 0.87816,0 1.54317,0.33752 1.98288,1.01267 l 0.42744,0.71655 0.42753,-0.71655 c 0.43961,-0.67515 1.10463,-1.01267 1.9828704,-1.01267 0.75893,0 1.37037,0.2668 1.83735,0.78727 0.45268,0.52046 0.67808,1.22395 0.67808,2.10922"/>
  </symbol>
</svg>

<footer class="footer">
  <div class="footer_inner wrap pale">
    <img src='https://kingdix10.gitee.io/icons/copy.svg' class="icon icon_2 transparent" alt="拾月国度">
    <p>Copyright&nbsp;2018-&nbsp;<span class="year"></span>&nbsp;拾月国度. All Rights Reserved</p><a class="to_top" href="#documentTop">
  <svg class="icon">
  <title>to-top</title>
  <use xlink:href="#to-top"></use>
</svg>

</a>

  </div>
</footer>

<script type="text/javascript" src="https://kingdix10.gitee.io/zh-cn/js/bundle.352f6b8ac853443fc909370d968a769ffa303b36042cc66849f2d48d9e5dd951ee86c06130908f5d77ea0e55ec8fed0e5dc26f0f14bbd4ad6dcf35999232e5bc.js" integrity="sha512-NS9rishTRD/JCTcNlop2n/owOzYELMZoSfLUjZ5d2VHuhsBhMJCPXXfqDlXsj&#43;0OXcJvDxS71K1tzzWZkjLlvA==" crossorigin="anonymous"></script>

  <script src="https://kingdix10.gitee.io/js/search.min.b19f217359693afb8f0abd75ca8de6becceec41f5304950fc48e165914ef227f44d10005d02a281a66e33b482e2ff27e6eb893111505deb4f072c307e1f887bb.js"></script>

  </body>
</html>
